Posted 7 months ago. Visible to the public.

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":

Copy
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

Copy
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

Copy
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.

makandra has been working exclusively with Ruby on Rails since 2007. Our laser focus on a single technology has made us a leader in this space.

Owner of this card:

Avatar
Michael Leimstädtner
Last edit:
7 months ago
by Michael Leimstädtner
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Michael Leimstädtner to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more