I figured out I can show old versions of a file using 'git log filename' to show the commits, and then use 'git show commit-id:filename' for the old version. But it just puts it in less.
I would like to be able to view this in emacs, so I can navigate as I'm used to and so that there is syntax highlighting. I found out I can't set the git core.pager to emacs since emacs cannot read from stdin.
Does anyone know how I could do this? Or do you have another good way of checking old versions of files?
Git file History provides information about the commit history associated with a file. To use it: Go to your project's Repository > Files. In the upper right corner, select History.
git checkout recovers old versions of files.
To reset a file back to an old version, you’ll need to find the commit ID from when you want to reset to. You can use git log for this, scoped to a single file to view only the changes done to that file: Copy the ID for the commit, and then run git checkout with the ID and file path:
This can come in handy when you want to check against a certain version for instance. You can also specify a commit hash (often also called commit ID) with the git show command. Show the log of all the changes for a given file with git log /path/to/file
If you came to this question because you want to check an older version of a binary file (e.g. an image), then better to do a checkout to the old commit, see what you need to see, and then come back to the HEAD. For that, do git checkout <sha1-of-the-commit-you-need>, afterwards, git checkout HEAD
As we saw earlier, using the git checkout command and supplying a filename as the first and only argument will checkout that file from HEAD. If you need to checkout a file version farther back than the HEAD branch, you can supply two arguments instead.
Just use >
and put it into a file that you can open in emacs.
git show commit-id:filename > oldfile
Then open the file in emacs.
If you are using bash
, you can use Process Substitution.
gvim <(git show commit-id:filename)
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