【问题标题】:How can I continue merging after a double-modify?双重修改后如何继续合并?
【发布时间】:2011-04-18 08:03:47
【问题描述】:

我正在使用git rebase -i 重写历史记录——在这种情况下,对较早提交的更改集进行小改动。换句话说,

A---B---C master

      --->

A---B'--C master

我知道C 也在隐式变化,但你明白了。这是我到目前为止的进展:

  1. git rebase -i HEAD~2
  2. Bkeep 更改为 edit
  3. 编辑文件。
  4. git commit -a --amend
  5. git rebase --continue
  6. “无法应用 [C]...”

我已经解决了C 中的冲突行,但我不确定如何将其标记为已解决,以便 rebase 可以继续。 git commit --amend 尝试修改 B,而 git rebase --continue 抱怨工作树很脏。 (而且,果然,git status 将文件显示为“都已修改”。)

我需要做什么才能让这个变基重回正轨?

【问题讨论】:

    标签: git conflict rebase


    【解决方案1】:

    当您遇到冲突时,您应该会看到如下消息:

    error: could not apply 45cb26a... <commit message subject>
    hint: after resolving the conflicts, mark the corrected paths
    hint: with 'git add <paths>' and run 'git rebase --continue'
    

    而这正是你需要做的:

    # resolve the conflicts somehow
    git add <conflicted-file>
    git rebase --continue
    

    不要尝试使用commit --amendHEAD(当前提交)仍然是指之前的那个,因为冲突阻止了这个提交,所以正如你所看到的,这只是修改了已经应用的提交。 rebase --continue 将继续进行包含已解决冲突的新提交。

    【讨论】:

    • 完美运行!感谢您的帮助,我错过了输出中的那一行。 ;-)
    • @Ben:这很容易错过,因为只要您知道自己在做什么,您就会立即解决冲突,而忘记上面的任何事情。
    【解决方案2】:

    您是否尝试过明确地这样做,即:git add B',然后使用 --amend 提交它,然后执行 git rebase --continue

    【讨论】:

    • 不会创建一个新的提交吗?我只是想让C 申请。
    • 对不起,我的意思是明确添加 B',然后执行 commit --amend。
    • 我已经修改了B 并尝试继续。现在,我的 repo 处于 B' 是日志中最近提交的状态,但来自 C 的更改已应用(包括我为解决冲突而进行的其他更改)。
    • 我看到你在做 git commit -a --amend。修改是否创建了新的未跟踪文件?否则当你给 git rebase --continue 时应该没问题
    • @manojlds — 当我看到 commit --amend 想要进一步修改 B'(我认为这会压缩两个提交)时,我中止了它。
    猜你喜欢
    • 2014-12-18
    • 2019-03-20
    • 2019-12-06
    • 2015-02-23
    • 1970-01-01
    • 1970-01-01
    • 2020-06-30
    • 2019-05-02
    • 1970-01-01
    相关资源
    最近更新 更多