我正在尝试使用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}
答案 0 :(得分:0)
对于0000000000000000000000000000000000000000
oldObjectId,它用于创建新分支,否则您需要指定提交sha。
答案 1 :(得分:-1)
是正确的:
对于0000000000000000000000000000000000000000000000 oldObjectId,它用于创建新分支,否则您需要指定提交sha。
但是,应该是您要使用的分支中最近发布的提交的完整SHA,而不是第一次提交。