星期一, 4月 09, 2012

將檔案庫中某子目錄抽出為獨立檔案庫

我們有下面這樣的檔案庫結構,Repo 下面有三個子目錄:DirA, DirB, DirC
Repo/DirA
Repo/DirB
Repo/DirC

現在我們想將 DirA 抽出來,獨自為一檔案庫。

製作目前檔案庫備份
$ git clone Repo temp
$ cd temp
將 remote 移除
temp/:$ git remote rm origin
抽出 DirA
temp/:$ git filter-branch --subdirectory-filter DirA HEAD
temp/:$ cd ..
重製檔案庫
$ git clone --bare temp DirA.git

參考來源:

http://progit.org/book/ch6-4.html

Making a Subdirectory the New Root

Suppose you’ve done an import from another source control system and have subdirectories that make no sense (trunk, tags, and so on). If you want to make the trunk subdirectory be the new project root for every commit, filter-branch can help you do that, too:
$ git filter-branch --subdirectory-filter trunk HEAD
Rewrite 856f0bf61e41a27326cdae8f09fe708d679f596f (12/12)
Ref 'refs/heads/master' was rewritten
Now your new project root is what was in the trunk subdirectory each time. Git will also automatically remove commits that did not affect the subdirectory.

沒有留言: