You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

创建GitHub Deployment时禁用自动合并仍遇409冲突,求解决

问题描述

我正尝试通过GitHub API创建Deployment。根据官方文档说明:

auto_merge boolean
当请求的ref落后于默认分支时,尝试自动将默认分支合并到该ref中。
默认值:true

由于我不希望启用自动合并,已经传入参数auto_merge=false,使用的命令如下:

gh api \
  --method POST \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  /repos/${{ github.repository }}/deployments \
    -f "ref=123"
    -f "auto_merge=false"

但我仍收到以下错误:

gh: Conflict merging main into 123. (HTTP 409)
{"message":"Conflict merging main into 123.","documentation_url":"https://docs.github.com/rest/deployments/deployments#create-a-deployment","status":"409"}

请问我忽略了什么?

解决办法

你忽略了两个关键问题:

  1. 命令语法错误:原命令里-f "auto_merge=false"前缺少反斜杠,导致这个参数根本没被传递给API,API还是用了默认的auto_merge=true,触发了合并操作和冲突错误。
  2. 分支最新性检查:即便正确设置auto_merge=false,GitHub Deployment API默认仍会要求目标分支与默认分支保持同步,否则会阻止创建Deployment。

修正后的命令如下:

gh api \
  --method POST \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  /repos/${{ github.repository }}/deployments \
    -f "ref=123" \
    -f "auto_merge=false" \
    -f "required_contexts=[]"

说明:

  • 补上反斜杠确保所有参数被正确传递,让auto_merge=false生效。
  • 添加required_contexts=[]参数,跳过所有分支最新性验证和状态检查,允许直接在落后于默认分支的ref上创建Deployment。

内容的提问来源于stack exchange,提问作者Sig

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 23:50:54