Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show a file from a specific commit that has been renamed between that commit and HEAD?

Tags:

git

I know that to show a file at a certain commit, I use git show <commit>:<file path>. But this doesn't work if the file was renamed between the commit and HEAD, so is there a way to easily do this on the file without needing to manually figure out what the original filename was at that commit?

like image 417
Gary Avatar asked Nov 20 '22 03:11

Gary


1 Answers

You could start with:

git log --oneline --name-only -M -C -- afile

That would detect any rename, and allow you to check if:

  • your <commit> is part of that list
  • what is the actual name associated with that commit

Then you can use the right filename for git show <commit>:<file path>.

Note, in git 2.9 (June 2016):

  • diff activates rename detection by default,
  • log --follow improves rename detection

So make sure to use git 2.9 as well.

like image 200
VonC Avatar answered Nov 22 '22 16:11

VonC