Arshak Anj
Arshak Anj

Reputation: 189

How to solve merge conflict in a approved review in gerrit?

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.)

Upvotes: 16

Views: 36838

Answers (2)

Sven Döring
Sven Döring

Reputation: 4368

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

Upvotes: 2

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

Upvotes: 39

Related Questions