可以使用Git Submodule和Git subtree两种方式进行合并。
Git Submodule:
- 在目标仓库中添加远程子模块:git submodule add -b
- 将子模块拉取到本地:git submodule update --init
- 在目标仓库中更新子模块:git submodule update --remote
- 复制子模块文件到目标仓库中:cp -R /*
Git subtree:
- 在源仓库中增加子目录:git subtree split --prefix= --branch=
- 将分支推送到目标仓库:git push :
- 在目标仓库中拉取分支:git subtree add --prefix=
示例代码:
Git Submodule:
- git submodule add -b master https://github.com/example/submodule.git ./submodule
- git submodule update --init
- git submodule update --remote
- cp -R ./submodule/* ./target_folder/
Git subtree:
- git subtree split --prefix=folder1 --branch=subtree_branch
- git push https://github.com/example/target.git subtree_branch:target_branch
- git subtree add --prefix=target_folder https://github.com/example/target.git target_branch