Resolving merge conflicts: Difference between revisions

From OSM Public Wiki
Jump to: navigation, search
No edit summary
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
__TOC__


In some cases it is possible to resolve merge conflicts issues using simple rebase triggered directly from the Gerrit UI. However, in other cases some choices and updates need be done to resolve the conflicts that cannot be done using the Gerrit UI.


These are the steps to follow to resolve the conflict and update the commit on Gerrit so it can be merged.
'''This page is mainly intended for MDLs, which have to deal with merge conflicts in Gerrit.'''


==Simple Rebase using Gerrit UI==
In some cases, it is possible to resolve merge conflicts issues in Gerrit using simple rebase triggered directly from the Gerrit UI. Just click on "Rebase" button to rebase the change.


1. Get the last code from the repository
The behaviour is described in [https://gerrit-review.googlesource.com/Documentation/user-review-ui.html Gerrit Review UI]:
* git checkout master
*If the rebase is successful, a new patch set with the rebased commit is created.
* git pull origin master
*If the rebase fails, there are conflicts that have to be resolved manually.


You can specify the parent revision where to rebase. The defaults are:
*If the change does not depend on another open change, it is rebased onto the tip of the destination branch.
*If the change depends on another open change, it is rebased onto the current patch set of that other change.
==When "Rebase" button is not enough==
In other cases, some choices and updates need be done manually to resolve the conflicts that cannot be done using the Gerrit UI. '''We strongly recommend the use of "git-review" tool''', as described in '''[[Using git-review to push and review changes|this link]]'''.
Optionally, you can use git and these steps to resolve the conflict manually and update the commit on Gerrit so it can be merged. The following steps assume that the commit is against master branch. You will have to change master to the right branch, if you are trying to review a different branch.
1. Get the last code from the repository. '''Note''': use the appropriate branch instead of master
git checkout master
git pull origin master


2. Create a new branch to work on the code with conflicts. You can use the review number and patchset as name.
2. Create a new branch to work on the code with conflicts. You can use the review number and patchset as name.
* git checkout -b <review-number>-<patchset>
git checkout -b <review-number>-<patchset>
 


3. Pull the patch on the created branch.  
3. Pull the patch on the created branch.  
(To find the command to execute you can open the corresponding change page on Gerrit UI, click on download menu, then copy the "pull" command.)
(To find the command to execute you can open the corresponding change page on Gerrit UI, click on download menu, then copy the "pull" command.)
* git pull <url> <ref>
git pull <url> <ref>
 
 
Note: The two previous steps could be simplified using [https://www.mediawiki.org/wiki/Gerrit/git-review git-review] tool. The following command takes as input the review number, it creates a local branch and pull the change on it automatically.
* git review -d <review-number>
 
 
4. Make a rebase of your branch against master
* git rebase master


4. Make a rebase of your branch against master. '''Note''': use the appropriate branch instead of master
git rebase master


5. Fix all conflicts that cannot be resolved manually using your editor.
5. Fix all conflicts that cannot be resolved manually using your editor.


6. Add all updated files to the index.
6. Add all updated files to the index.
# git add <file>  
git add <file>  
 
Note: You can use git-status to make sure that conflicts are solved
* git status


'''Note''': You can use git-status to make sure that conflicts are solved
git status


7. Continue the rebase process using the following command
7. Continue the rebase process using the following command
* git rebase --continue
git rebase --continue
 
 
8. Submit your change back to the repository
* git push origin HEAD:refs/for/master
 


Note: If you are using git-review tool, the previous step could be done with the following command
8. Submit your change back to the repository. '''Note''': use the appropriate branch instead of master
* git review


git push origin HEAD:refs/for/master


9. Go back to Gerrit UI. You will find the change waiting for review.
9. Go back to Gerrit UI. You will find the change waiting for review.

Latest revision as of 13:49, 24 March 2017


This page is mainly intended for MDLs, which have to deal with merge conflicts in Gerrit.

Simple Rebase using Gerrit UI

In some cases, it is possible to resolve merge conflicts issues in Gerrit using simple rebase triggered directly from the Gerrit UI. Just click on "Rebase" button to rebase the change.

The behaviour is described in Gerrit Review UI:

  • If the rebase is successful, a new patch set with the rebased commit is created.
  • If the rebase fails, there are conflicts that have to be resolved manually.

You can specify the parent revision where to rebase. The defaults are:

  • If the change does not depend on another open change, it is rebased onto the tip of the destination branch.
  • If the change depends on another open change, it is rebased onto the current patch set of that other change.

When "Rebase" button is not enough

In other cases, some choices and updates need be done manually to resolve the conflicts that cannot be done using the Gerrit UI. We strongly recommend the use of "git-review" tool, as described in this link.

Optionally, you can use git and these steps to resolve the conflict manually and update the commit on Gerrit so it can be merged. The following steps assume that the commit is against master branch. You will have to change master to the right branch, if you are trying to review a different branch.

1. Get the last code from the repository. Note: use the appropriate branch instead of master

git checkout master
git pull origin master

2. Create a new branch to work on the code with conflicts. You can use the review number and patchset as name.

git checkout -b <review-number>-<patchset>

3. Pull the patch on the created branch. (To find the command to execute you can open the corresponding change page on Gerrit UI, click on download menu, then copy the "pull" command.)

git pull <url> <ref>

4. Make a rebase of your branch against master. Note: use the appropriate branch instead of master

git rebase master

5. Fix all conflicts that cannot be resolved manually using your editor.

6. Add all updated files to the index.

git add <file> 

Note: You can use git-status to make sure that conflicts are solved

git status

7. Continue the rebase process using the following command

git rebase --continue

8. Submit your change back to the repository. Note: use the appropriate branch instead of master

git push origin HEAD:refs/for/master

9. Go back to Gerrit UI. You will find the change waiting for review.