在Git rebase过程中解决合并冲突后是否需要提交?

19

我将另一个分支 rebase(变基) 到我的 checkout 分支上,但在 rebase 过程中出现了冲突。我解决了合并冲突。

$ git status
rebase in progress; onto 77c951b
You are currently rebasing branch 'test' on '77c951b'.
  (all conflicts fixed: run "git rebase --continue")

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   br_boss_buha_faktura/forms/br_boss_buha_faktura_head_dtl.frm
        modified:   br_boss_buha_faktura/valuelists/br_boss_buha_faktura_client.val
        new file:   br_boss_buha_faktura/valuelists/br_boss_buha_faktura_client_name.val

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   br_boss_buha_faktura/valuelists/br_boss_buha_faktura_client.val
我需要提交已解决的合并冲突 git commit 吗?还是可以直接使用 git rebase --continue 继续进行?

我需要提交已解决的合并冲突git commit吗?还是可以直接使用git rebase --continue继续进行?

4个回答

22

这里有一些好的回答,但是为了回答问题。,在解决合并冲突后,您不需要提交。

一旦您通过git add <file>将解决方案添加到git暂存区,使用git rebase --continue使用原始提交消息为您创建提交

注意提交哈希值将发生更改!因此,当您将其合并到另一个分支中时,该分支具有您在自己的分支中更改的提交时,将会出现合并问题。


注意,我说过在解决git rebase冲突后你不需要git commit,但如果你愿意,你可以这样做。

如果有必要,可以将一个提交中的文件拆分成多个单独的提交,以使其更加合理。通常情况下,您只需解决冲突即可。如此示例所示:Break a previous commit into multiple commits


2
所以你不需要这样做。好的,如果您的答案也能解释一下在继续变基之前提交会发生什么,那就太好了。 - init_js

4

我在这里看到

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   br_boss_buha_faktura/valuelists/br_boss_buha_faktura_client.val

请执行

git add br_boss_buha_faktura/valuelists/br_boss_buha_faktura_client.val

那么

git rebase --continue

1
在执行了 git add 之后,是否真的需要执行 git commit -a 呢? - BuZZ-dEE
好的,请执行 git commit -a。 - Gopi
你的特性分支(topic_branch)里有多少次提交是很重要的。假设你只有一次提交,那么你可以解决冲突并执行 git add 和 git commit 命令。如果有超过 1 次的提交,那么你就需要执行 git rebase --continue 命令。即使只有一次提交,你也可以执行 git rebase --continue 命令(更加安全)。 - Gopi
这并没有真正回答我的问题。 - BuZZ-dEE
让我们在聊天中继续这个讨论。点击此处进入聊天室 - Gopi
显示剩余3条评论

1
如果您提交了更改,我相信您可以执行 git rebase --skip 跳过现在不存在的合并冲突。

1

执行 git rebase --continue 命令会将当前正在应用的提交重写为您更改后的形式。它会使用在 test 分支中相同的名称提交更改。

请注意,您正在对一个提交进行变基,可能处于分离 HEAD 状态!通常情况下,人们会在 master 或者 staging 分支上进行变基。


那么我不需要使用 git commit 吗?我修复它,然后只需使用 git rebase --continue?你说的“通常,人们会在主分支或暂存分支上进行变基”是什么意思?我现在在 test 分支上,并已经将 git rebase featureA 应用到了 test 分支上。 - BuZZ-dEE
是的,就像文档告诉你的那样。另外,正如@pala所说,你有一个文件没有被提交。这是故意的还是应该成为当前rebase提交的一部分? - rubenvb
是的,我已经弄清楚了,我需要添加文件 git add br_boss_buha_faktura/valuelists/br_boss_buha_faktura_client.val,因为 git rebase --continue 无法工作,并且我收到消息 You must edit all merge conflicts and then mark them as resolved using git add - BuZZ-dEE

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接