tags:

views:

1697

answers:

2

Is there a command in git to see (either dumped to stdout, or in $PAGER or $EDITOR) a particular version of a particular file?

+12  A: 

You can use git show:

$ git show REVISION:path/to/file

For example, to show the 4th last commit of the file src/main.c, use:

$ git show HEAD~4:src/main.c

For more information, check out the man page for git-show.

mipadi
That doesn't actually seem to work -- did you try it? For "git show HEAD:path/to/file.c", I get an "ambiguous argument" error.
mike
And if I just do "git-show path/to/file.c", the command succeeds with no output.
mike
Yeah, I tried it out -- it worked for me.
mipadi
With what version of git? The other way to do it is with git cat-file given the blob ID (which you can find with ls-tree, but that's the hard way).
Dustin
git version 1.5.6.3
mike
Has to be the complete path, from the top of the git repo
rq
If you're on windows, it might be a path separator thing; if I do git show HEAD:dir\subdir\file, I get the anbiguous argument. If I do git show HEAD:dir/subdir/file, it works as expected.
Matt McMinn
+1  A: 

The path you must provide after the : is from the root of the git repository.