Gerrit random questions for now.
My change had a "path conflict", how do I rebase / merge it?[edit | edit source]
For the impatient:
Full explanation[edit | edit source]
So you have submitted a change and was approved. But by the time it gets reviewed other commits have altered the main repository which now cause a conflict. Gerrit is unable to automatically merge your change into the repository, you will have to fix it and resubmit the change.
The example below is based on a real use case : change 2514 using the operations/puppet repository
First fetch the change using git-review and its -d option :
(production)$ git-review -d 2514 Downloading refs/changes/14/2514/1 from gerrit into review/hashar/ignore_pyc Switched to branch 'review/hashar/ignore_pyc' (review/hashar/ignore_pyc)$
hashar is the user name, ignore_pyc the topic name he gave. Notice how git-review automatically placed you to the branch.
You now have to rebase on top of the main branch. The change on gerrit shows the branch, just add "gerrit/" in front. For this change in the operations/puppet repo, the main branch is "production", so rebase on gerrit/production; for other repos it's usually origin/master.
(review/hashar/ignore_pyc)$ git rebase gerrit/production
First, rewinding head to replay your work on top of it... Applying: pyc files are now ignored Using index info to reconstruct a base tree... Falling back to patching base and 3-way merge... Auto-merging .gitignore CONFLICT (content): Merge conflict in .gitignore Failed to merge in the changes. Patch failed at 0001 pyc files are now ignored When you have resolved this problem run "git rebase --continue". If you would prefer to skip this patch, instead run "git rebase --skip". To check out the original branch and stop rebasing run "git rebase --abort". (no branch)$
The key in the above output is the line starting with CONFLICT. It tells you the filename that git couldn't cleanly rebase, usually because your patch alters it and changes in the main branch have also altered it. Running git status confirms it:
(no branch)$ git status # Not currently on any branch. # Unmerged paths: # (use "git reset HEAD <file>..." to unstage) # (use "git add/rm <file>..." as appropriate to mark resolution) # # both modified: .gitignore # (no branch)$
Edit the conflicting file (in this case .gitignore). This will have
>>> markers surrounding the conflicting lines, you must clean this up. During the merge conflict git creates file.BASE.xxx, file.LOCAL.xxx, and file.REMOTE.xxx files with the three source versions. You can use a three-way merge tool to pick which lines to use; git mergetool wraps the use of a merge tool.
Once you have finished editing, you have to add that modification to have it used during the rebase then continue fixing any conflicting patches:
(no branch)$ git add .gitignore (no branch)$ git rebase --continue Applying: pyc files are now ignored (review/hashar/ignore_pyc)$
Since there was no more patches to fix, you have been placed back in the review/hashar/ignore_pyc branch. Looking at the log:
$ git log -n5 --decorate --pretty=oneline * a3631d2 (HEAD, review/hashar/ignore_pyc) pyc files are now ignored (2 seconds ago * 1b6cd67 (gerrit/production, production) ensure sample config file removed (18 hours ago) ...
Verify you change looks fine before resubmitting it to gerrit. Just use git show <sha1 of commit>, i.e. git show a3631d2. You can eventually amend it to state you have rebased the change.
Now submit your change back in the repository:
(review/hashar/ignore_pyc)$ git review remote: Resolving deltas: 0% (0/2) To ssh://<someuser>@gerrit.wikimedia.org:29418/operations/puppet.git (review/hashar/ignore_pyc)$
Heading back to Gerrit, the change is a new patchset pending review:
Congratulations on fixing your first rebase / merge conflict!
git review warns about submitting other people's commits[edit | edit source]
Sometimes when running git review, you get a warning saying you're about to submit multiple commits, followed by a list of other people's commits that have already been merged.
If this happens, the workaround is
- respond "no" to abort git-review.
- run git fetch gerrit
- rerun git-review
This will ensure git-review has an up-to-date view of the remote master.
Background[edit | edit source]
Roan fixed this in 2012 in https://review.openstack.org/#/c/6741/ , the bug returned in the latest release of git-review that came out in April. Change https://review.openstack.org/#/c/20450/ reintroduced the broken behavior. WMF projects suffer from this disproportionately because we have defaultrebase=0 set on most of our projects, and the bug only triggers when rebasing is disabled (using either that setting or the -R flag).