我的一个朋友指出我要Moving files from one git repository to another, preserving history。过滤器分支指令不适用于我,可能是因为我的回购没有分支机构?无论如何,我做的是:
git clone <git repository A url>
cd <git repository A directory>
git remote rm origin
git filter-branch --subdirectory-filter <directory 1> --
这给了我一个回购,只有在子目录的变化。然后,我融入我的第二个回购这样的:
git clone <git repository B url>
cd <git repository B directory>
git remote add repo-A-branch <git repository A directory>
git pull repo-A-branch master
git remote rm repo-A-branch
然后我用滤波器分支从主回购删除子目录:
git filter-branch --tree-filter 'rm -rf <bad subdirectory>' --prune-empty HEAD
最后我也跟着The power of Git subtree更新后的第二次回购添加到第一作为子树。