2015-06-08 36 views
4

比方说,我有我的东西一个git回购目录myapp内:Git的节目的文件路径

myapp 
    /.git 
    /.gitignore 
    /subdirA 
     /subdirB 
      /file1.txt 
      /file2.txt 
      /(and some other stuffs) 
    /(and some other stuffs) 

我想从旧查看file1.txt提交abcd123。对于another thread,我才知道,我应该使用类似:

$ git show abcd123:path/to/file1.txt 

然而,我感到困惑的正确的道路使用。我试着像

$ git show abcd123:myapp/subdirA/subdirB/file1.txt 
$ git show abcd123:subdirA/subdirB/file1.txt 
$ git show abcd123:subdirB/file1.txt 
$ git show abcd123:file1.txt 

但混帐一直给我像

$ Path 'subdirA/subdirB/file1.txt' does not exist in 'abcd123' 

如何解决这个问题的错误消息?

+4

你可以得到一个有效的路径列表int他承诺'git ls-tree -r --name-only abcd123' –

+0

@ WumpusQ.Wumbley非常感谢。有用。我可以查看我现在需要的文件。在上面的例子中,路径“subdirA/subdirB/file1.txt”应该是正确的,但我可能错误地键入了路径,以致于收到错误消息。 – user740006

+0

@ WumpusQ.Wumbley这是值得写一个答案) –

回答

2

该命令将产生中存在的评论abcd123路径列表:

git ls-tree -r --name-only abcd123 

任何你从这个命令得到应该作为一个工作路径为git show abcd123:...

此外,它更容易,有时使用在路径上领先./。这会自动将.替换为从存储库根目录到工作树中当前目录的路径。例如:

cd ~/my-git-repo/dir1/dir2 
git show abcd123:./Makefile # equivalent to git show abcd123:dir1/dir2/Makefile 

如果你尝试git show abcd123:Makefile它不工作...但混帐不建议(“你的意思是......?”)都从库根和完整路径版本版本与./ ...除非你在abcd123的根目录中也有Makefile,在这种情况下,你只是没有警告,你可能想要./Makefile