对于D2方面
git remote add [name-for-D1-repo] [D1-repo-url]
git fetch --all
git merge [name-for-D1-repo]/[D1-working-branch] --allow-unrelated-histories
git fetch --all。--allow-unrelated-histories 标志是相对较新的;如果 git merge 拒绝它,那么你只需要使用一个假定该标志始终存在的旧版本 Git。 - torek我的建议是选择一个仓库作为主要仓库(比如说first-repo),在那里创建一个分支(比如说the-other-repo),然后将the-other-repo的最新版本(不使用git命令,只需简单复制)转储/复制到first-repo的工作目录中,使得the-other-repo成为HEAD,提交更改,然后将the-other-repo分支合并到first-repo的“master”分支的HEAD中。
如果想保留提交历史记录,可以进行变基。
--allow-unrelated-histories选项(请参见David Guan的回答)。在任何情况下,Git用作“共同基础”的实际上是空树,因此,与此合成合并基础相比,两个分支末端都完全由“添加所有文件”组成。这有时是您想要的,有时不是。 - torek