2012-11-05 87 views
4

有沒有辦法只從git倉庫下載給定的子目錄?假設我只想從https://github.com/djdeath/toys.git獲取nyancat目錄。有沒有辦法只從git下載子目錄?

我可以克隆整個存儲庫並忽略不需要的文件,或者轉到https://github.com/djdeath/toys/tree/master/nyancat並逐一下載相關文件。我認爲必須有一個更簡單的方法。

注意我不是問是否有可能克隆的目錄,這是asked before,顯然是不可能的。我只是想快速獲取這些文件,而不需要重新提交,或者再次使用它們。

+0

缺乏這種能力是git最糟糕的事情。 –

回答

2

git-archive命令會做很多你想要的東西,但它需要對已經克隆回購操作,因此,如果你有到主機SSH訪問,你可以這樣做:

cd /path/to/destination 
ssh [email protected] "cd /path/to/repo && git archive HEAD dir/you/want" | tar xf - 

或者,與網絡傳輸壓縮:

cd /path/to/destination 
ssh [email protected] "cd /path/to/repo && git archive HEAD dir/you/want | gzip" | tar xzf - 
0

嘿,我剛剛wrote a script

使用

 python get_git_sub_dir.py path/to/sub/dir <RECURSIVE> 
相關問題