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?
The Git Show command allows us to view files as they existed in a previous state. The version can be a commit ID, tag, or even a branch name. The file must be the path to a file. For example, the following would output a contents of a file named internal/example/module.go file from a tagged commit called “release-23”.
Git has three main states that your files can reside in: modified, staged, and committed: Modified means that you have changed the file but have not committed it to your database yet. Staged means that you have marked a modified file in its current version to go into your next commit snapshot.
To check the status, open the git bash, and run the status command on your desired directory. It will run as follows: $ git status.
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
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.
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