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?
You could start with:
git log --oneline --name-only -M -C -- afile
That would detect any rename, and allow you to check if:
<commit>
is part of that listThen 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 detectionSo make sure to use git 2.9 as well.
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