tags:

views:

37

answers:

2

I want to show the contents of a file given by a path at a specific state of a git repo. I unsuccessfully tried this:

git show f825334150cd4bc8f46656b2daa8fa1e92f7796d:Katana/source/Git/GitLocalBranch.h
fatal: ambiguous argument
'f825334150cd4bc8f46656b2daa8fa1e92f7796d:Katana/source/Git/GitLocalBranch.h': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions

The commit in question didn't modify the file specified. How can I show the contents of a file at a given state (specified by a commit hash) regardless of the involvement of the file in the commit?

+1  A: 

The syntax you're using matches that shown in the examples for the git show manpage, but git seems to be hinting that you should specify like this:

# I _don't_ think this is your answer...
git show f825334150 -- Katana/source/Git/GitLocalBranch.h

which I've definitely used for git log and is in its manpage.

My gut, though, tells me that you using an absolute path and not the path inside the top of your git work tree. You need to make sure that if your .git directory is at Katana/source/Git/.git, then you chop off everything before the .git, like so:

git show f825334150:GitLocalBranch.h

If you're trying to show a git blob from outside the git working area, you need to do something like this:

GIT_DIR=Katana/source/Git git show f825334150:GitLocalBranch.h

This will tell git where it can find the data for the your repository.

Bottom line: double-check your paths and make sure they're right. You might need to set a GIT_DIR if you're not running your command from inside the git work area.

MikeSep
Katana/source/Git/GitLocalBranch.h is a relative path from the base git directory
richcollins
Well, that's right, then. Is `f82533` a commit? You can check its type by running `git cat-file -t f82533`.
MikeSep
Just checked that `git show commitHash:path/to/file` works fine for me when referring to a file not changed in the commit.
MikeSep
+1  A: 

It's probably problem with your path specification.

This works, shows version of Makefile in commit b1b22df407417...

git show b1b22df407417:Makefile

Or current version in master branch

git show master:Makefile

Or current version in exper branch:

git show exper:Makefile

Or previous version on the exper branch:

git show exper^:Makefile

And so on

stefanB
I'm pretty sure that it isn't a problem with the path. I think the problem is that the file wasn't modified by the commit. I get the same result for any file that wasn't modified by the commit.
richcollins
Oh ok, I assumed that you selected specific version because you know that the file was modified in it.
stefanB