2
我有一個git存儲庫,我想將它變成兩個git存儲庫,但是拆分並不像看上去那麼簡單git filter-branch --subdirectory-filter
想要的。根據任意文件路徑拆分Git存儲庫
myRepo/
a-main.js
b-main.js
a-other.js
tests/
a-tests.js
b-tests.js
我想要做的是得到另一個只有a-*
文件的存儲庫。 請注意,爲了清楚起見,我已經以這種方式對它們進行了命名,實際的文件沒有共同的模式。只有少數,所以單獨列出它們都沒有問題。
我已經試過:
git clone --no-hardlinks ~/myRepo ~/myRepoA
cd ~/myRepoA
git filter-branch --tree-filter "rm b-main.js tests/b-tests.js" \
--prune-empty HEAD
但這給出了這樣的輸出
Rewrite 4ce7... (1/46)rm: cannot remove `b-main.js': No such file or directory
rm: cannot remove `tests/b-tests.js': No such file or directory
tree filter failed: rm b-main.js tests/b-tests.js
獎勵積分:
一旦做到這一點,我該怎麼辦把它推到Github上的新庫中?
一個技巧是使用--index過濾器代替--tree過濾器的,因爲 - 索引過濾器在索引上運行,所以不需要git來檢出每個提交,例如: git filter-branch --index-filter「git rm -f --cached --ignore-unmatch b-main .js tests/b-tests.js「--prune-empty --tag-filter cat HEAD 我還添加了--tag-filter cat來重寫標籤 – ralphtheninja