1
mohamed: 2:31
msaid: 2:41
<<<<<<< HEAD
mohamed: 2:52
=======
msaid: 2:55
>>>>>>> msaid_test/test

This is the final product after merging a branch with the master branch.

This was the content of the file in master branch before merge:

mohamed: 2:31
msaid: 2:41
mohamed: 2:52

And this was the content of the file in msaid_test/test branch:

mohamed: 2:31
msaid: 2:41
msaid: 2:55

I was trying to learn how to solve conflicts using Sourcetree and Bitbucket, Why are these line appearing? <<<<<<< HEAD and >>>>>>> msaid_test/test. and What is the right way of resolving conflicts?

Mohamed Said
  • 4,413
  • 6
  • 35
  • 52

4 Answers4

5
content common to both branches
<<<<<<< HEAD
content only in HEAD, aka the master branch
=======
content only in other_branch
>>>>>>> other_branch
content common to both branches

The strings <<<<<<< HEAD, =======, and >>>>>>> other_branch are just markers that indicate what text was present in each branch. It is up to you to take this information and edit the file to determine the correct version. This will probably include removing the markers, and often will consist of choosing one set of content or the other. Sometimes you will choose to write something new, or otherwise merge the changes.

Neil Forrester
  • 5,101
  • 29
  • 32
4

It is the case of conflicts. That is, Your master branch contain mohamed: 2:52 as third line and file contains msaid: 2:55. <<<<<<< HEAD indicates of beginning of conflict code and >>>>>>> msaid_test/test indicats the ending. You can solve it by editing the code as what you need. And Push again it to your master.

Sajeev
  • 783
  • 3
  • 14
  • 46
3

Assuming you want to merge from test into master.

mohamed: 2:31  # unchanged stuff
msaid: 2:41  # unchanged stuff
<<<<<<< HEAD  # HEAD = last commit of the current branch (master)
mohamed: 2:52  # stuff from master that is not in test
=======
msaid: 2:55  # stuff from test that is not in master
>>>>>>> msaid_test/test

Just edit the file to how it should look in the end.

Markus Unterwaditzer
  • 7,992
  • 32
  • 60
3

E.g. You've merged B branch into A branch, but met some conflict, then git will mark them in this way:

The content between <<< HEAD & === is the source of A (the target branch), and the content between === & >>> B is the source of B. You need to manually fix this conflict by yourself.

Suppose you want to keep the B's source, then you need to delete

>>> HEAD
content
===

otherwise, delete another part

===
content
<<< B

after you've fix all conflicts, commit the source.

Note: The finally resource should not contains these marks. You should manage them all.

Kjuly
  • 34,476
  • 22
  • 104
  • 118