How to solve merge conflict in a approved review in gerrit?
Asked Answered
I

2

15

I made a change in gerrit which was code reviewed and after 7 revisions approved. But, now it cannot be merged and trying to rebase in gerrit website is not working due to merge conflict. How can I resolve this merge conflict and merge the same approved change and not create a new one. (Full steps from cloning the repo would be appreciated.)

Intramuscular answered 8/11, 2018 at 13:59 Comment(0)
F
39

1) Clone the Gerrit repository

git clone https://USER@GERRIT-SERVER/a/REPO-FULL-PATHNAME

2) Go to the change page on Gerrit and copy the checkout patch command

git fetch https://USER@GERRIT-SERVER/a/REPO-FULL-PATHNAME refs/changes/XX/YYYYY/Z && git checkout FETCH_HEAD

3) Rebase the change

git rebase origin/BRANCH

4) Solve the conflicts

git mergetool

5) Continue the rebase

git rebase --continue

Repeat the steps 4 and 5 until the end of conflicts

git commit --amend

Note: Keep the same Change-Id

6) Send the new patchset to Gerrit

git push origin HEAD:refs/for/BRANCH
Fender answered 8/11, 2018 at 17:34 Comment(4)
Tip for readers: If you already have a repo and don't want to git clone again, you can use 'git fetch' to replace the first command.Condemnation
Actually, if you already have a repo you can just skip the first step. The "git fetch" will already be executed in step 2.Falla
I think you missed git add . after git mergetool. You need to do it before git rebase --continueYolondayon
I think "git add" is not necessary.Falla
O
2

The accepted solution works but I personally disagree with this workflow. It is unnecessarily cumbersome.

I prefer a workflow with exactly one merge and therefore less steps.

  1. Clone the Gerrit repository if not already available
    git clone https://[USER]@[GERRIT-SERVER]/a/[REPO-FULL-PATHNAME]
    
  2. Checkout the Gerrit patch
    git fetch https://[USER]@[GERRIT-SERVER]/a/[REPO-FULL-PATHNAME] refs/changes/46/12346/N && git checkout FETCH_HEAD
    
  3. Soft-reset the change and stash it
    git reset --soft HEAD~1 && git stash
    
  4. Checkout branch or the Gerrit patch you want to rebase onto
    git checkout origin/BRANCH
    # or fetch other Gerrit patch:
    # git fetch https://[USER]@[GERRIT-SERVER]/a/[REPO-FULL-PATHNAME] refs/changes/45/12345/N && git checkout FETCH_HEAD
    
  5. Unstash the previously stashed changes
    git stash pop
    
  6. Solve the conflicts with your favourite 3-way merge tool.
  7. Commit the merged changes - NOT (!!) amend them - and use the same Change-Id from the merged patch in the message:
    git commit -am "[COMMIT-MESSAGE]\
    \
    Change-Id: [FORMER-CHANGE-ID]"
    
  8. Send the new patchset to Gerrit
    git push origin HEAD:refs/for/BRANCH
    

Done. One merge!


I additionally use the gitreview tool. That makes it extra easy. Steps 2, 3, 4 and 5 then can be chained.

git review -d 12346 && git reset --soft HEAD~1 && git stash && git review -d 12345 && git stash pop
Otho answered 3/3, 2022 at 20:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.