0

There are a few answers about getting the most recent commit for a file. The answers boil down to "git log --all --pretty=format:%H -- path."

Note the --all to search the whole graph.

git log is very slow. It seems to take a few seconds per operation which is painful when you've got thousands of files to look at. Is there a faster plumbing way to do this?

3
  • git log should be instantaneous. you can also use the -n 1 option to limit to 1 commit, since you only want the most recent. Don't know if it will speed up but it's worth a try. Also, if you are on windows, there are other reasons git could be slow in general Commented Jul 2, 2015 at 22:16
  • 1
    git log itself is almost instantaneous. git log -- path is not. Commented Jul 2, 2015 at 23:18
  • Edited to note use of --all. Commented Jul 2, 2015 at 23:29

1 Answer 1

1

You can use this command. This works very fast for me on a large repository that I work on (million lines of code with history going back 10 years).

git log -n 1 -- filename 
  • The -n 1 gives you the most recent commit
  • The -- filename narrows down git log to just the filename that you want
Sign up to request clarification or add additional context in comments.

4 Comments

This is too slow, as stated in the question. Is there something I should investigate as to why it is so slow?
Edited to note use of --all.
If the last commit on a file was a long time ago, it may take a while before git will find it. Git has to, essentially, search for the pathname in each commit's object. Then, if the branch had a lot of merges, git has to branch out from each merge, searching each parent's history, etc...
Some of the files almost certainly are quite old, but others are not and the time taken seems to be similar.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.