我想使用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}}}}
正文:
文档: 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
}
一条评论指出这是应该采取的路线。还指出应该使用repositoryId
和newObjectId
,其结果为:
{
"$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
}