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