Here’s a great Git tip if you want to view an older version of a file on a certain branch / commit. As with other things with Git, there’s more than one way to cook an egg.
Prerequisites
- Git
Solution
#1 git diff
Step 1. cd
to your working tree directory and find the commit ID (SHA-1) by listing commits with git log
.
git diff <commit-SHA1> <relative_path_file>
Example:
git diff e8581zt /api/main.go
git diff
shows the differences between the specified commit and whatever our HEAD points to at the moment.
#2 git show
Instead of git diff
, use:
git show <commit-SHA1> <relative_path_file>
Example:
git show e8581zt /api/main.go
git show
points the details shown with git diff
as well as the commit details: commit ID, author, date and message.
Conclusion
To find more neat Git commands and hacks, simply browse the Git category. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.