Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git show old version of file in editor

Tags:

git

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?

like image 816
kodu Avatar asked Aug 09 '13 13:08

kodu


People also ask

How do I see revision history in git?

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.

Which command is used to explore the previous versions of a project?

git checkout recovers old versions of files.

How to reset a file back to an old version in Git?

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:

How do I see changes in a specific version of Git?

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

How to check an older version of a binary 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

How do I Checkout a file from another branch in Git?

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.


2 Answers

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.

like image 92
Schleis Avatar answered Sep 30 '22 16:09

Schleis


If you are using bash, you can use Process Substitution.

gvim <(git show commit-id:filename) 
like image 29
Nimlar Avatar answered Sep 30 '22 16:09

Nimlar