Azure DevOps API - 从主分支创建新分支且不添加更改

4
我想使用Azure DevOps服务的Rest API从主分支创建一个新分支,但一直没有成功。
文档: https://learn.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
}

一条评论指出这是应该采取的路线。还指出应该使用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
}
1个回答

2

newObjectId是现有分支的对象ID。不确定为什么它被命名为“new”,实际上它更旧。非常奇怪。

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

2
他们可能称其为“new”,因为这是相应的“ref”需要保持的新value。虽然任何涉及json数据的内容都不属于Git,但这也是Git术语。 - torek

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接