Wink Saville’s Blog

June 13, 2009

Viewing an old version of a file in git

Filed under: What I learned today — wink @ 8:03 am

Use “show” command, but you need to use the full path from the root of the git repo to the file, otherwise you’ll get an error such as below. This same error happens if there is any other error in the parameter, for instance a miss-spelling:

$ git show HEAD:hxy
fatal: ambiguous argument ‘HEAD:hxy’: unknown revision or path not in the working tree.
Use ‘–’ to separate paths from revisions

Anyway, to look at a particular file use can use git log to see the various revisions:

$ git log –pretty=oneline -3 help.c
746c221ad063854e23661f6898c002c8726f5dad git wrapper: also use aliases to correct mistyped commands
277cd4c4bd8cca31395846fc80ea28bf2cd4ddf2 Merge branch ‘ar/autospell’
f0e90716d47b429284702b75425a247c9fc41adb Add help.autocorrect to enable/disable autocorrecting
$ git show f0e90716d47b429284702b75425a247c9fc41adb:help.c

To see the current version you’d could use the the first entry.


$ git show 746c221ad063854e23661f6898c002c8726f5dad:help.c

To see the previous version use the second sha1:


$ git show 277cd4c4bd8cca31395846fc80ea28bf2cd4ddf2:help.c

I wonder if there is a simple syntax to get a particular revision such as:


$ git show REV^:help.c

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URL

Sorry, the comment form is closed at this time.

Powered by WordPress