If you just want to find the most recent commit, then you don't want git-log
, you want git-rev-list
, which lists the commit objects changing that file, in that commit path, starting with the most recent one (chronologically). Simply put:
git rev-list -1 <commit> <filename>
For git-rev-list
in your case, you just supply:
- The number of commits to include, or -1 for only the most recent,
- The branch (or commit id) to start looking back from, HEAD if you are already on it, or --all if you want all known commits, and
- The relative path to your file.
This just returns the most recent commit ID in the current branch to alter that file, ex: 215095e2e338525be0baeeebdf66bfbb304e7270
For a more complex example, you can use tag names, and even remote references, and include relative path names with wildcards, for ex:
git rev-list origin/user/bob/testbranch -1 src/bfiles/*.txt
...Which would tell you what the most recent change was to the wildcard match in that branch's history. The options for rev-list are extreme, it is one of the most important plumbing commands, so you can include or exclude by just about any criteria you can imagine.
Of course, refer to the git-rev-list(1) Manual Page.