【问题标题】:merge two git repositories - consistent history合并两个 git 存储库 - 一致的历史记录
【发布时间】:2017-06-22 09:06:20
【问题描述】:

我发现了一些类似的主题,但请看看我的解决方案。看起来 git subtree 旨在解决一个稍微不同的问题。我有两个存储库 A 和 B。存储库 B 只有一个与存储库 A 内容无关的目录。我只想将该目录添加到 repo A 并在 repoA 中有一个一致的历史记录。 Repo B 将不再使用。

以下是步骤:

cd RepoB
git checkout develop
git remote set-url origin RepoA
git pull origin develop
git push -u origin develop

git pull 将执行合并,我应该使用 fetch 然后与一些选项参数合并吗?

您还有其他建议吗?

【问题讨论】:

  • 这里的“一个一致的历史”是什么意思?您是否需要保留 A 和 B 的更改历史?历史记录是否必须准确地反映在对 B 的更改之前对 A 进行了更改,但对 B 的更改是在对 A 的其他更改之前进行的,等等?

标签: git


【解决方案1】:

您可以尝试将 RepoB 重新设置在 RepoA 之上:

repoA/master:  A--B--C--D
repoB/master:  X--Y--Z

Result: A--B--C--D--X--Y--Z

通过运行

cd repoA
git remote add repoB git@server:repoB
git fetch repoB
git checkout repoB/master  # replace branch name if needed
git rebase master  # replace branch name if needed

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-28
    • 1970-01-01
    • 2012-10-14
    • 1970-01-01
    • 2014-12-17
    相关资源
    最近更新 更多