How to show an older version of a committed file using Git
So, somewhere down the line you made some commits and now, for whatever reason, you need to go back and see what a particular file looked like at some point in time. Well, with Git it’s a super-easy one-liner. First, you’ll need to know what commit contains a copy of that file in the state in question. This shouldn’t be too hard as long as you’re keeping your commit messages nice and informative. :wink:
git log --oneline
Will output a list of your previous commits in a condensed format with only the hashid and description. Find the one in question and then copy the hashid. Then press ‘q’ to get out of the pager and run the following:
git show hashid:path/to/file.php
Annnnd…you’re welcome! You can even pipe it out using standard out to a copy somewhere for further analysis:
git show hashid:path/to/file.php > /somewhere/safe/file.bk.php
Hope this little snippets helps you!