Azure DevOps API - 从 master 创建新分支而不添加更改

Azure DevOps API - Create new branch from master without adding changes

我正在尝试使用 Azure DevOps Services Rest API 从 master 创建一个新分支,但我一直没有成功。

文档:https://docs.microsoft.com/en-us/rest/api/azure/devops/git/refs/update-refs?view=azure-devops-rest-5.1#examples

端点:https://dev.azure.com/{{organization}}/{{project}}/_apis/git/repositories/{{repositoryId}}/refs?api-version={{api-version}}

正文:

[
  {
    "name": "refs/heads/new-test-branch-from-api-call",
    "oldObjectId": "{{masterObjectId}}",
    "newObjectId": "{{newObjectId}}"
  }
]

结果:

{
    "$id": "1",
    "innerException": null,
    "message": "TF401035: The object '****************************************' does not exist.",
    "typeName": "Microsoft.TeamFoundation.Git.Server.GitObjectDoesNotExistException, Microsoft.TeamFoundation.Git.Server",
    "typeKey": "GitObjectDoesNotExistException",
    "errorCode": 0,
    "eventId": 3000
}

this post 的评论指出这是要采取的路线。还指出应该使用 repositoryIdnewObjectId 结果:

{
    "$id": "1",
    "innerException": null,
    "message": "An object ID must be 40 characters long and only have hex digits. Passed in object ID: ********-****-****-****-************.",
    "typeName": "System.ArgumentException, mscorlib",
    "typeKey": "ArgumentException",
    "errorCode": 0,
    "eventId": 0
}

newObjectId是现有分支的对象id。真的不确定为什么它实际上是旧的而被命名为新的。很奇怪。

[
  {
    "name": "refs/heads/new-test-branch-from-api-call",
    "newObjectId": "{{BranchObjectIdGoesHere}}",
    "oldObjectId": "0000000000000000000000000000000000000000"
  }
]