Gary
Gary

Reputation: 4241

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

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?

Upvotes: 4

Views: 58

Answers (1)

VonC
VonC

Reputation: 1326676

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

So make sure to use git 2.9 as well.

Upvotes: 1

Related Questions