2011-02-02 64 views
3

從廣義上講,我想要的是一個直接的tar-tar轉換,其結果的根目錄只包含原始的特定目錄子樹。如何使用git-archive獲得GNU tar的-strip-components的效果?

舉一個例子來說明,比如說我只需要git倉庫中的gitweb directory。運行

$ git archive --prefix=git-gitweb/ master gitweb | tar tf -

git-gitweb/ 
git-gitweb/gitweb/ 
git-gitweb/gitweb/INSTALL 
git-gitweb/gitweb/Makefile 
git-gitweb/gitweb/README 
git-gitweb/gitweb/gitweb.perl 
git-gitweb/gitweb/static/ 
git-gitweb/gitweb/static/git-favicon.png 
git-gitweb/gitweb/static/git-logo.png 
git-gitweb/gitweb/static/gitweb.css 
git-gitweb/gitweb/static/gitweb.js

,但我想

git-gitweb/ 
git-gitweb/INSTALL 
git-gitweb/Makefile 
git-gitweb/...

manual提供額外的特定於後端的選項,而是試圖通過--strip-components產生一個錯誤:

$ git archive --prefix=git-gitweb/ --strip-components=1 master gitweb | \ 
    tar tf - 
error: unknown option `strip-components=1' 
usage: git archive [options] [...] ...

無論如何,tar後端並不是GNU tar。

有人在freenode上的#gnu通道建議Tardy,但它不理解的git-archive輸出:

$ git archive master > old.tar 
$ tardy old.tar new.tar 
tardy: old.tar: file type ``g'' unknown

是的,我可以--strip-components提取混帳存檔的輸出,並創建一個新的存檔結果,但我試圖避免使用文件系統作爲臨時變量。

回答

7

存檔該目錄爲CWD,你會不會有額外的路徑組件:

(cd gitweb; git archive --prefix=git-gitweb/ master .) | tar tf - 

或使用該語法由git-archive手冊頁的建議:

git archive --prefix=git-gitweb/ master:gitweb | tar tf - 
+0

大,它使用`--remote`選項來git-archive也一樣! – 2011-02-02 16:15:39