VSTS REST推送api返回409

时间:2018-01-18 23:44:06

标签: git rest azure-devops

我正在尝试使用push api更新我的仓库中的文件但总是得到409响应。请告知我是否做错了。

以下是请求:

POST  https://{myaccount}.visualstudio.com/defaultcollection/{myteam}/_apis/git/repositories/{myrepo}/pushes?api-version=3.0 HTTP/1.1

Authorization: Basic <token>
Host: {myaccount}.visualstudio.com
Content-Type: application/json
Content-Length: 493

{
  "commits": [
    {
      "Comment": "Some comment",
      "Changes": [
        {
          "Item": {
            "Path": "somepath/test.json"
          },
          "ChangeType": 1,
          "NewContent": {
            "Content": "test"
          }
        }
      ]
    }
  ],
  "refUpdates": [
    {
      "name": "refs/heads/somebranch",
      "oldObjectId": "0000000000000000000000000000000000000000"
    }
  ]
}

我得到了409回复:

{"$id":"1","innerException":null,"message":"TF401028: The reference 'refs/heads/mybranch' has already been updated by another client, so you cannot update it. Please try again.","typeName":"Microsoft.TeamFoundation.Git.Server.GitReferenceStaleException, Microsoft.TeamFoundation.Git.Server","typeKey":"GitReferenceStaleException","errorCode":0,"eventId":3000}

2 个答案:

答案 0 :(得分:0)

对于0000000000000000000000000000000000000000 oldObjectId,它用于创建新分支,否则您需要指定提交sha。

  1. 转到代码页&gt;文件
  2. 选择存储库和分支
  3. 选择根级别(存储库名称)&gt;历史
  4. 点击第一次提交的...&gt;复制完整的SHA

答案 1 :(得分:-1)

是正确的:

对于0000000000000000000000000000000000000000000000 oldObjectId,它用于创建新分支,否则您需要指定提交sha。

  1. 转到代码页>文件
  2. 选择存储库和分支
  3. 选择根级别(存储库名称)>历史记录
  4. 单击上次提交的…>复制完整的SHA

但是,应该是您要使用的分支中最近发布的提交的完整SHA,而不是第一次提交。