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