2012-06-13 64 views
22

是否有一個命令可以接受一個ref和一個文件路徑,並輸出文件的完整內容,就像它在提交到STDOUT時那樣?Git:整個文件到標準輸出

EG。是這樣的:

git show-me-the-file HEAD~2 some/file | do_something_with_piped_output_here 
+3

git cat-file -p HEAD〜2:some/file – jthill

+0

謝謝jthill - 也可以。讓它成爲答案,我會對它投票。 – Joel

+0

這是我用它的:meld <(git cat-file -p HEAD:some/file)<(git cat-file -p master:some/file);用於查看meld中文件的差異。可能有更好的方法來做到這一點,但似乎運作良好。 – Joel

回答

38

git show

例如

git show HEAD:./<path_to_file>

+3

'|貓'是不需要的(除非你想阻止尋呼機踢)。 –

+0

「:」很重要,否則你會看到差異而非完整文件。 –

7

git show <ref spec>:<path> 例如,如果你想看到一個文件在提交點9be20d1bf62你這樣做:

git show 9be20d1bf62:a/b/file.txt

,如果你想查看某個分支的文件:

git show <branch name>:<path>

2

你想要git showgit archive這個用例。不過,git-show命令更傾向於將文件發送到標準輸出。

# Show .gitignore from revision before this one. 
git show HEAD^:.gitignore 

冒號之前的部分是根據gitrevisions(7)形成的樹肥胖型,而後者則是一半相對於你的git工作樹的頂部的路徑。