How to: "git log" with renamed files

While renaming a file sometimes feels like "dropping its history", that is not true: Just use git log --follow on renamed files to access their full history.

Given a file "bar" that was previously named "foo":

touch foo
git add foo
git commit -m "Add foo"
mv foo bar
git add bar
git commit -m "Rename foo to bar"

git log bar

commit adc8e6a05b65355359c4e4618d6af0ed8f8b7f14 (HEAD -> git-follow)
Author: Michael Leimstaedtner <makmic@makandra.de>
Date:   Wed May 12 08:49:37 2021 +0200

    Rename foo to bar

git log --follow bar

commit adc8e6a05b65355359c4e4618d6af0ed8f8b7f14 (HEAD -> git-follow)
Author: Michael Leimstaedtner <makmic@makandra.de>
Date:   Wed May 12 08:49:37 2021 +0200

    Rename foo to bar

commit b2699e28d213cb610c016b0bc584d64a648735b1
Author: Michael Leimstaedtner <makmic@makandra.de>
Date:   Wed May 12 08:48:58 2021 +0200

    Add foo

The --follow option only works for single files.

Michael Leimst├Ądtner about 1 year ago
This website uses short-lived cookies to improve usability.
Accept or learn more