我有一个结构如下的项目:
src/
scripts/
db/
other_stuff/
even_more_stuff/
file1
file2
file3
这个存储库需要拆分。文件夹 db 和 scripts 需要拆分到它们自己的存储库中,我知道这可以通过
git filter-branch --subdirectory-filter ...
轻松完成
我还需要根据当前结构(包括历史记录)创建一个新的主存储库,但排除任何已拆分到其自己的存储库的内容或要排除的特定文件列表中的任何文件:
file1
,file3
,even_more_stuff
。有没有办法使用 git filter-branch
过滤掉特定名称的文件?
最终的主存储库应该是:
src/
other_stuff/
file2
其中一个问题是我不应该对原始存储库进行任何更改,因此我不能只删除
file
、file3
等...然后将其余部分复制到新存储库。
好的,这是我使用 git-filter-repo:
的方法cd my-source-repo
git filter-repo --path src --path other-stuff --path file2
git log
看起来没问题。cd my-target-repo
git remote add src-repo path/to/my-source-repo
git pull src-repo main --allow-unrelated-histories
git remote rm src-repo
git push --set-upstream origin main
(在适当的情况下更改分支名称。)
我只做过一次,所以我不知道是否有更短、更简单的方法,但这仍然比使用
git filter-branch
更好。