使用Azure DevOps REST Api如何获取分支的提交哈希?

时间:2019-02-03 01:12:56

标签: git rest tfs azure-devops azure-devops-rest-api

到目前为止,我想出了以下URL(本地TFS):

http://{TFS Server}:8080/tfs/DefaultCollection/{Team Project}/_apis/git/repositories/{Repo Name}/refs?filter=heads&api-version=4.1

但是它返回所有分支。我怎样才能得到我需要的东西?

1 个答案:

答案 0 :(得分:1)

使用此API:

http://{TFS Server}:8080/tfs/DefaultCollection/{Team Project}/_apis/git/repositories/{Repo Name}/stats/branches/{Branch Name}?api-version=4.1

示例响应:

{
  "commit": {
    "commitId": "87fbec24ec18e2d48ef978f0cxxxxxxxxxx",
    "author": {
      "name": "Shayki Abramczyk",
      "email": "shayki5@gmail.com",
      "date": "2019-01-15T18:35:36Z"
    },
    "committer": {
      "name": "Shayki Abramczyk",
      "email": "shayki@gmail.com",
      "date": "2019-01-01T18:35:36Z"
    },
    "comment": "Added Code",
    "url": "https://dev.azure.com/shaykia/xxxxxxxx/_apis/git/repositories/815cc0c7-5f3e-404bxxxxxxxx/commits/xxxxxxxx8ef978f0cf356646d089fee7"
  },
  "name": "FeatureBranch",
  "aheadCount": 2,
  "behindCount": 0,
  "isBaseVersion": false
}