Skip to content

Merge conflicts

Daniil Timofeev edited this page Sep 24, 2023 · 5 revisions

Introduction

What is a merge conflict?

Merge conflicts occur in version control systems (Git) when two or more branches or change-sets cannot be automatically merged because they contain conflicting changes to the same part of a file or code-base.

Reasons for conflicts

Conflicts generally arise when two developers have changed the same lines in a file, or if one developer (A) deleted a file while another developer (B) was modifying it. In these cases, Git cannot automatically determine what is correct. Conflicts only affect the developer conducting the merge, the rest of the team is unaware of the conflict. Git will mark the file as being conflicted and halt the merging process. It is then the developers' responsibility to resolve the conflict.

How to resolve merge conflicts?

Git modifies the conflicting files to include special markers that indicate where the conflicts occur. These markers typically look like this:

<<<<<<< HEAD
// Your changes
=======
// Their changes
>>>>>>> branch_name
  • <<<<<<< HEAD indicates the start of your changes.
  • ======= separates your changes from the other branch's changes.
  • >>>>>>> branch_name indicates the start of the other branch's changes.

How to resolve conflicts using WebStorm?

  1. First and foremost, you should open Git menu (ALT + 9).

  2. You should find local dev and update it.

image

  1. Then you should perform Rebase label/name-of-your-branch onto dev .

image

  1. In this menu you should choose Merge. Hint : you must choose neither Accept Theirs, nor Accept Yours.

image

  1. In the central part of this menu you should add necessary changes (both from dev and from yours). Only after this message 'All changes have been processed', you click the Apply button. Nota Bene! In some cases you should write code in order to handle changes from both sides.

image

  1. Rebase successful means that you` have done everything right.

image

  1. Usually, the amend commit is done automatically when there are no other changes in the file, except for the Rebase (only a force push is done)