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.
Find what file changed in a commit To find out which files changed in a given commit, use the git log --raw command. It's the fastest and simplest way to get insight into which files a commit affects.
Git file History provides information about the commit history associated with a file. To use it: Go to your project's Repository > Files. In the upper right corner, select History.
Use --follow option in git log to view a file's history This lists out the commits of both the files.
The git log command displays all of the commits in a repository's history.
You can simplify it a little bit like this:
git log --format='%H' --name-only --follow -- README.md
which will give you output kind of like this
621175c4998dfda8da README.md d0d6ef0a3d22269b96 README.md
which should be a little easier to parse. For instance you can use a sentinel and sed out the newlines like this:
git log --format='%H%%' --name-only --follow -- README.md | sed ':a;N;$!ba;s/%\n\n/ /g'
which should give you the hash and the filename on the same line:
621175c4998dfda8da README.md d0d6ef0a3d22269b96 README.md
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With