Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"
   }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...