libgit2sharp icon indicating copy to clipboard operation
libgit2sharp copied to clipboard

Get commit where a given file was last modified

Open ToomasT opened this issue 9 years ago • 3 comments
trafficstars

Trying to emulate the following, it outputs the SHA of the commit this particular file was changed last: git rev-list -1 HEAD file.ext Here git-rev-list is listed under low-level plumbing commands, but I could not find how to actually use it anywhere? How can rev-list be called with libgit2sharp or if it can not, is there any other way to get the commit where a given file was last modified?

ToomasT avatar Aug 17 '16 08:08 ToomasT

I'm actually looking for feedback on something I came up with that may solve this issue for you. I'd like to know if what I came up with is an adequate means of acquiring the last 5 commits on a given file. I could not find anything in the lib that you can call out of the box.

This appears to work for me, but I'd appreciate some feedback from anyone who knows the libGit2Sharp libraries better than I do...

https://gist.github.com/damon1977/50eb700898bece46a4569dd9e032a768

damon1977 avatar Sep 19 '16 23:09 damon1977

I am also looking for a solution like this. I have one file and I want to get the latest commit using LibGit2Sharp library. Thank you for providing this solution. I tried in my project, but it is not returning or may be not loading the result. I am still wondering that why I am not able to see the result on below line.

var last5 = repo.Commits.Where(filter).OrderByDescending(c => c.Author.When).Take(5);

I copied the same code. Am I doing something wrong? is my file path wrong?

Would you please help me?

JignaJoshi avatar Mar 29 '21 12:03 JignaJoshi

Also looking for a solution that is performant. I need to get this information from a repository for many thousands of files (there are hundreds of thousands of files, and nearly as many commits)

davidcorbin-atmosera avatar Jun 13 '22 14:06 davidcorbin-atmosera