"HEAD" in the middle of the code after merge

0

I made merge between branch develop and master and some conflicts appeared, but I ended up solving it. The problem is that I saw two files in which it has <<<<<<< HEAD in the middle of the code of branch master . I ended up removing this part manually, but since there were several affected files in merge , I think there might be some more with this problem.

I found that by doing merge again this would sort, because develop does not have these errors, then it would delete master , but it does not modify anything (only new changes).

Would you have any way to fix this? Or even at the time of doing merge replace all files from master to develop ?

    
asked by anonymous 26.04.2018 / 02:31

1 answer

3

This is the conflict indicator. If you give git status you can see that you are in the middle of a conflict resolution yet. Or if you're not ... it means you did lame. It means that you have committed a "conflict resolution" that included this marker (along with ======= and >>>>>>>>> develop ).

Git only makes that mark when it can not handle itself to resolve the changes. The case where git does not know how to deal with this is when there are two changes in the same context.

For example, imagine that I have this C-like code:

if (num % 2 == 1) 

Then, in develop , someone changes to:

if (num % 2)

But I, in master , change to:

if (num & 1)

How will git proceed? It will identify that the common basis of the two codes was:

if (num % 2 == 1)
  

Note for the next paragraphs: line of code prefixed with - indicates line removed , already line prefixed with + indicates line added

That develop is the following operation:

-    if (num % 2 == 1)
+    if (num % 2)

The change in master is the following operation:

-    if (num % 2 == 1)
+    if (num & 1)

That means there were two different actions

-    if (num % 2 == 1)
+    if (num % 2)
     

and

-    if (num % 2 == 1)
+    if (num & 1)

for the same context (original line if (num % 2 == 1) ). The maximum git can get from here is that the original line has been removed, but it will not know what action to take. To do this, it will generate more or less the following after the merge attempt ( git merge develop ):

<<<<<<<<<< HEAD
    if (num & 1)
==========
    if (num % 2)
>>>>>>>>>> develop

With this, it is up to the human to decide what he is going to do with this is, and then only, to tell git that the conflict has been solved. This conflict case is solved by doing git add meu/arquivo/conflito.c to list each conflict resolution, then confirmed with a git commit traditional.

This by far is the most common conflict case I have in developing in the company where I work. There are other cases of conflict, with changes in the same context, type, I changed the file but Articuno decided to delete it in its branch. When attempting to merge, git will complain that there was a "change / removal" type conflict.

Sometimes the conflict does not imply that both heads have actually deleted the same line and inserted their change. I've had conflicts like this:

Base file:

int x;
int a;

Head patch-1 :

int x;
-int a;
+int a = 2;

Head patch-2 :

int x;
int a;
+char *palavra;

In this case, the post merge would look something like this:

int x;
<<<<<<<<<< HEAD
int a = 2;
==========
int a;
char *palavra;
>>>>>>>>>> patch-2

Note that here git was confused as to whether or not to remove the line int a; , because in one of the branches it was actually deleted, while in the other I just attached it.

    
26.04.2018 / 07:48