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.)
How to solve merge conflict in a approved review in gerrit?
Asked Answered
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
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 --continue
–
Yolondayon I think "git add" is not necessary. –
Falla
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.
- Clone the Gerrit repository if not already available
git clone https://[USER]@[GERRIT-SERVER]/a/[REPO-FULL-PATHNAME]
- Checkout the Gerrit patch
git fetch https://[USER]@[GERRIT-SERVER]/a/[REPO-FULL-PATHNAME] refs/changes/46/12346/N && git checkout FETCH_HEAD
- Soft-reset the change and stash it
git reset --soft HEAD~1 && git stash
- 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
- Unstash the previously stashed changes
git stash pop
- Solve the conflicts with your favourite 3-way merge tool.
- 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]"
- 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
© 2022 - 2024 — McMap. All rights reserved.