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

混江龙づ霸主 提交于 2019-12-12 02:32:28

问题


I am trying to get the history for one particular item in one particular branch in my git repository, using the Team Service REST API (https://www.visualstudio.com/en-us/docs/integrate/api/git/commits).

I have this structure in my repository.

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

How can I get the commits for just Item1 in Branch1?

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

with JSON:

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

But this gives me the commits for the whole branch. How can I get the commits for just that item in that particular branch?


回答1:


There isn't any direct way to get this with Rest API for now, you can submit a feature request on VSTS User Voice.

The alternative way to achieve this would be get all the commits in specified branch and get all the commits for specified item, and then list the commits exist in both scenarios.




回答2:


It is actually possible to do it exactly with commitsBatch. You don't have to get all branches and all commits and compare...

You do a POST to

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

and the JSON String is:

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


来源:https://stackoverflow.com/questions/37805335/get-commits-of-an-item-in-one-branch-with-tfs-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!