commit相互依賴,gerrit merge提示git submit including parents

一、關鍵字

  • 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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章