2015-06-08 34 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