如果你想合并project-a
into project-b
:
cd path/to/project-b
git remote add project-a /path/to/project-a
git fetch project-a --tags
git merge --allow-unrelated-histories project-a/master # or whichever branch you want to merge
git remote remove project-a
取自:git 合并不同的存储库? https://stackoverflow.com/questions/2949738/git-merge-different-repositories
这种方法对我来说非常有效,它更短,而且在我看来更干净。
如果你想把project-a
进入子目录,您可以使用git-filter-repo https://github.com/newren/git-filter-repo (filter-branch
is 灰心 https://git-scm.com/docs/git-filter-branch#_warning)。在上述命令之前运行以下命令:
cd path/to/project-a
git filter-repo --to-subdirectory-filter project-a
合并 2 个大存储库,将其中一个放入子目录的示例:https://gist.github.com/x-yuri/9890ab1079cf4357d6f269d073fd9731 https://gist.github.com/x-yuri/9890ab1079cf4357d6f269d073fd9731
Note: The --allow-unrelated-histories
参数仅自 git >= 2.9 起才存在。看Git - git merge 文档 / --allow-unrelated-histories https://git-scm.com/docs/git-merge#git-merge---allow-unrelated-histories
Update: Added --tags
按照@jstadler的建议,以保留标签。