【问题标题】:Azure DevOps API - Create new branch from master without adding changesAzure DevOps API - 从 master 创建新分支而不添加更改
【发布时间】:2022-01-14 14:17:38
【问题描述】:

我正在尝试使用 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 帖子上的评论指出这是要采取的路线。还指出应该使用 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
}

【问题讨论】:

    标签: azure azure-devops branch azure-devops-rest-api


    【解决方案1】:

    newObjectId 是现有分支的对象 ID。真的不知道为什么它实际上是旧的时被命名为新的。很奇怪。

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

    【讨论】:

    • 大概他们称之为“新”,因为它是对应的 ref 需要保持的新 value。这也是 Git 的术语,尽管像这样涉及 json 数据的任何东西都在 Git 之外。
    猜你喜欢
    • 2019-04-12
    • 2018-09-08
    • 2018-12-23
    • 2020-12-23
    • 1970-01-01
    • 2011-04-22
    • 1970-01-01
    • 2019-07-16
    • 2021-10-05
    相关资源
    最近更新 更多