一、关键字

  • git
  • submit
  • including
  • parents
  • commit相互依赖

二、问题场景

gerrit merge冲突“git submit including parents”根本原因commit相互依赖提交。是用户push了commit A,在commit A基础上提交了commit B,在commit B基础上提交了commit C,如下图(上)。这种场景大多出现在多人同时在往一个分支上提交代码,用户提交完后,没有及时审核并合并代码;其他用户在之后提交了代码,并进行了合并,用户早些时候提交的代码有冲突。用户此时在Gerrit上abandon了commit B,在B基础上继续提交了commit C,则Gerrit会出现git submit including parents,如下图(下)。

在这里插入图片描述

三、解决方式

1、从远程分支上重新创建一个新的工作分支:git fetch origin master(远程分支):new_work(新分支)

$ git fetch origin master:temp_loongshawn
From ssh://xxxx.com.cn:123456/XXXX/XXXX/test
 * [new branch]      master     -> temp_loongshawn

2、 切换到新的工作分支:git checkout new_work

$ git checkout temp_loongshawn
Switched to branch 'temp_loongshawn'

3、将commit B 移到新分支上(gerrit 页面右上角download中直接复制cherry-pich命令):git fetch ssh://xxx xxx && git cherry-pich xxx

$ git fetch ssh://xxxx.com.cn:123456/XXXX/XXXX/test                                                                                                                                                            refs/changes/12/23456/1 && git cherry-pick FETCH_HEAD
From ssh://xxxx.com.cn:123456/XXXX/XXXX/test
 * branch            refs/changes/12/23456/1 -> FETCH_HEAD
error: could not apply l215478h... TFS-IT:123456
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

4、正常解决冲突流程,不做复述

xxxxxx@WIN-xxxxxxx xxxxxx /d/Work Space/test (temp_loongshawn|CHERRY-PICKING)
$ git status
On branch temp_loongshawn
You are currently cherry-picking commit l215478h.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Unmerged paths:
  (use "git add <file>..." to mark resolution)

        both modified:   test/test.java

no changes added to commit (use "git add" and/or "git commit -a")

5、正常提交代码:git push origin HEAD:refs/for/mater(需要提交到的分支)

git push origin HEAD:refs/for/mater

6、刷新gerrit,重新做code review

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐