David Greene
David Greene

Reputation: 414

Fastest way to get most recent commit for a file in git

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?

Upvotes: 0

Views: 112

Answers (1)

Biswajit_86
Biswajit_86

Reputation: 3739

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

Upvotes: 1

Related Questions