I have been trying to carry out some rebases and merges in different conditions in test repositories I have crested just for this reason.
Here is my understanding about merge conflicts, they arise basically when the feature branch has changes that differ from the changes of the master from the commit where they separate.
Here is my branch structure of the repository I am testing out.
C (feature)
/
B
/
A-----D (master)
Contents of each version are just a single file called file
A:
line 1
line 2
line 3
line 4
D:
changed line 1
line 2
line 3
line 4
B:
line 1
changed line 2
line 3
line 4
C:
line 1
changed line 2
changed line 3
line 4
Now when I execute git merge master feature
, I am shown a merge conflict with the following contents of my file,
<<<<<<< HEAD
line 1
changed line 2
changed line 3
||||||| 00f97ec
line 1
line 2
line 3
=======
changed line 1
line 2
line 3
>>>>>>> master
line 4
Here's my understanding of how git would go about merging the files:
- It would compare the 3 commits namely A, D and C.
- It would check whether C or D have added or deleted any line and also if A had it or not.
- Say C added a line which was neither in A nor added by D, then it would be in the final commit.
- The only case in which a conflict must arise is when either branch adds or deletes a line and the other branch makes modifications to the same line AND that same line should also be present in their last common ancestor ie A.
But this is not the case for my repository, then why are the conflicts arising. Please correct me if my understanding of merge conflicts is wrong.