Resolve a Merge Conflict
Git can automatically resolve code conflicts when the review branch is merged with the target branch. In some cases, however, the conflicts must be resolved manually.
On the Merge Request page, if the Merge button is replaced by the Merge Conflicts button, it indicates a merge conflict.
Git automatically resolves conflicts if different files of the target and review branches are updated before both branches are merged. Merge conflicts are reported when the same lines of the same files are updated in the review branch and the target branch before both branches are merged. Most people will use the browser-based conflict resolution tool:
-
On your computer, open the Git CLI.
-
If you’ve already cloned the project Git repository, navigate to its directory.
If you haven’t cloned the Git repository, clone it.
-
Run the commands shown on the Merge Conflicts dialog.
The commands help you resolve the conflict and mark the conflicting code lines in files.
-
Open each file that contains conflicts in a text editor.
Content with conflicts is marked with
<<<<<<<
,=======
, and>>>>>>>
. The lines between<<<<<<<
and=======
show the code from the target branch. The lines between=======
and>>>>>>>
show the code from the review branch. -
Review the content and update it. Remember to remove the
<<<<<<<
,=======
, and>>>>>>>
from each conflicting file before saving it. -
Save all files and commit them.
Run the
git status
command to view the status of conflicting files. -
Push the commit to the target branch.
Note:
If you see the message "Update requires 'Merge-Request' line present in the commit-message" when you are trying to push a commit to the remote repository, it doesn't indicate a merge conflict at all. It simply points to the fact that the remote repository you are pushing changes to is protected. The development branch in your remote repository has a merge restriction, possibly for Code review approval, before the MR can be merged. It was set up to only accept tags that point to commits with a specific commit message that starts with the text, "Merge-Request: ...". The remote repository was set up this way (Requires Review) to make sure that all changes (commits) have gone through the intended merge request workflow, where every change is reviewed and approved before being pushed.
Conflicting files in the review branch are now merged with the target branch. No additional action is required on the Merge Request page.