使用 TFS REST API 在一个分支中获取项目的提交

Get commits of an item in one branch with TFS REST API

我正在尝试使用 Team Service REST API (https://www.visualstudio.com/en-us/docs/integrate/api/git/commits).[=15 在我的 git 存储库的一个特定分支中获取一个特定项目的历史记录=]

我的存储库中有这个结构。

Repository1 -- Branch1 -- Item1 -- Item2 -- Branch2 -- Item1 -- Item3

如何在 Branch1 中获取 Item1 的提交?

我试过 POST: https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/commitsBatch?api-version=1.0

与 JSON:

{ "itemVersion": { "versionType": "branch", "version": "Branch1" } }

但这给了我整个分支的提交。我怎样才能获得那个特定分支中那个项目的提交?

目前没有任何直接方法可以通过 Rest API 获得此功能,您可以在 VSTS User Voice 上提交功能请求。

实现此目的的另一种方法是获取指定分支中的所有提交并获取指定项目的所有提交,然后列出两种情况下都存在的提交。

实际上完全可以使用 commitsBatch 来完成。您不必获取所有分支和所有提交并进行比较...

你做一个 POST 到

https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/commitsBatch?api-version=1.0

并且 JSON 字符串是:

 {
   "itemPath":
     "/Folder1/Folder2/item1.extention",
   "$top":250
   "itemVersion": {
     "versionType": "branch",
     "version": "Branch1"
   }
}