How can I show the contents of a file at a specific state of a git repo?

后端 未结 2 1027
猫巷女王i
猫巷女王i 2021-02-02 08:14

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 f825334150cd4bc8f46656b2daa8fa1e9         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-02 08:56

    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.

提交回复
热议问题