The git command
git log --format='%H' --follow -- foo.txt
will give you the series of commits that touch foo.txt, following it across renames.
I’m wondering if there’s a git log command that will also print the corresponding historical file name beside each commit.
It would be something like this, where we can interpret '%F' to be the (actually non-existent) placeholder for filename.
git log --format='%H %F' --follow -- foo.txt
I know this could be accomplished with
git log --format='%H' --follow --numstat -- foo.txt
but the output is not ideal since it requires some non-trivial parsing; each commit is strewn across multiple lines, and you’ll still need to parse the file rename syntax ("bar.txt => foo.txt") to find what you’re looking for.
You can simplify it a little bit like this:
which will give you output kind of like this
which should be a little easier to parse. For instance you can use a sentinel and sed out the newlines like this:
which should give you the hash and the filename on the same line:
For info on the sed invocation, see How can I replace a newline (\n) using sed? which has the answer I based that bit on.