【问题标题】:Merging One Repo Into Another Repo's History将一个回购合并到另一个回购的历史中
【发布时间】:2013-08-13 05:51:45
【问题描述】:

我们称原始源状态为 A。

我将状态 B 到状态 F 提交到 Repo 1。状态 B 表示状态 A 的修改版本。我犯了一个错误,即在 Repo 1 中没有提交状态 A 到 B。

在回购 2 中,我在状态 A 中添加了原始源的副本。然后我进行了更改,使其看起来像状态 B(不是字面上的状态 B,如回购 1 中的状态,而是类似于它的东西)。然后,我手动对状态 B 进行更改,使其看起来像回购 1 中的状态 F(不是字面意义上的状态 F,如回购 1 中的状态,而是类似的东西)。然后我从状态 F 到状态当前进行了更多更改。

我想将 Repo 1 和 Repo 2 合并为一个逻辑历史时间线。我不希望 Repo 2 中的任何当前文件(代表旧状态)处于 Repo 1 的当前状态。

最简单的方法是什么?有什么建议吗?

【问题讨论】:

标签: git version-control github


【解决方案1】:

听起来您需要将状态 A 添加为您的第一个 repo 的根。您可以在以下位置找到执行此操作的说明:

  1. git: how to insert a commit as the first, shifting all the others?
  2. Git: how to add commits before first/initial/root commit?
  3. How to add retro commits to a git repository?

您基本上想将状态 A 添加到孤立分支中的第一个 repo,然后使用 rebase--root--onto 标志将旧历史移动到 A 之上。

选项 2

不要创建一个状态为A 的孤立分支,另一种选择是将repo 2 硬重置为状态A,将repo 1 添加为远程,获取repo 1 的历史记录,然后将repo 1s 的历史重新设置为状态A:

# In repo 2
git reset --hard A
git add remote repo1 <path-or-url-to-repo1>
git fetch repo1
git checkout <branch-with-state-A>
git rebase --onto A --root repo1/<remote-branch-with-B-through-F>

【讨论】:

    猜你喜欢
    • 2013-07-18
    • 2017-08-29
    • 1970-01-01
    • 2012-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-04
    相关资源
    最近更新 更多