In this post I describe the solution I use to a common situation for people using gerrit. In other words, pretty much everyone who does MediaWiki development. I got this question on IRC and decided to write the answer down here, as I expect to get it more in the future, as well as me being unable to find it already on MediaWiki.org.
Context: A commit was made to a git repo and pushed to gerrit for code review. You want to merge it into master.
Problem: Some other commit got merged in after you branched of master, and this commit touches some of the same code. There is thus a conflict that cannot be automatically resolved, preventing you from merging it via gerrit. You know you have this problem when hitting the gerrit “rebase” button results in an error message like “The change could not be rebased due to a path conflict during merge.”
Desired solution: Resolving the conflict and updating the commit on gerrit so it can be merged.
Steps to take:
- Make sure you have the latest code from master locally. For instance by doing “git checkout master; git pull origin master”
- Get the commit you want to resolve a conflict for. Typically this is done via git review. “git review -d 12345″, where 12345 is the commit number you can see in the commit URL on gerrit.
- Start a rebase against master. “git rebase master”
- If you get lucky, git might actually be able to solve the conflict automatically after all. In which case you can skip this step and the next. More typically you’ll get at least one conflict that cannot be resolved and requires your attention to get fixed. You’ll get a list of these conflicts after running the rebase command and can also view them in a more concise form by doing “git status”.
- Fix each of the conflicts using your editor/IDE.
- Add the files in which conflicts occurred using “git add”. If you are done with this, doing a “git status” should result in there no longer being a “Unmerged paths” section.
- Finish your rebase using “git rebase –continue”. It is possible git runs into more conflicts, which will require you to repeat the last 3 points and this one until you got rid of them all.
- Submit the rebased commit to gerrit. “git review”
In short, this is the typical workflow:
- git pull origin master
- git review -d 12345
- git rebase master
- “fix conflicts”
- git add *
- git rebase –continue
- git review
Edit: There actually is a page on the same topic on MediaWiki.org.
Thanks!
On my machine it says: git: ‘review’ is not a git command. See ‘git –help’.
I had to install git-review for it to work. Please fix
This is the way that I follow, assuming the lastest commit is causing issues during merge
git reset –soft HEAD~1
git stash
git pull
git stash pop
git commit
During the git commit you might have to add the correct Change-Id for it to associate to
Thank you VERY MUCH! I appreciate your guide!