-
Notifications
You must be signed in to change notification settings - Fork 3
Merge conflicts
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.
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?
-
First and foremost, you should open Git menu (ALT + 9).
-
You should find local dev and update it.
- Then you should perform Rebase
label/name-of-your-branch
ontodev
.
- In this menu you should choose
Merge
. Hint : you must choose neitherAccept Theirs
, norAccept Yours
.
- In the central part of this menu you should add necessary changes (both from
dev
and fromyours
). Only after this message 'All changes have been processed', you click theApply
button. Nota Bene! In some cases you should write code in order to handle changes from both sides.
-
Rebase successful
means that you` have done everything right.
- 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)