-1

So there is master that goes

   m1->m2

and a branch that goes

     m1->m2
       \
        ->b1->b2 

I did a merge of master into branch making it

   m1->m2         mb(merge commit)
        \       /
         ->b1->b2

Say i have had a conflict in one file that i fixed in branch while merging master. i fixed it and it now looks nothing like how the file looks in master ( at commit m3). if i merge the branch ( now at commit mb) back into master, git does not complain that there is a conflict. is the file not different? how does it know its not a conflict and it needs to use the file coming from the branch ?

I get that its the right behavior but i am just curious what tells git that the one in branch is the 'right' one.

5
  • The fixed conflict is merged into master so the conflict is fixed.
    – dan1st
    May 31, 2021 at 19:47
  • roughly, It's a matter of checking the differences that the separate branches introduced against the last common ancestor. When you merge master into branch X, when you try to merge X into master, the last common ancestor between both branches would be master (if it hasn't moved). So whatever changes you introduced into X will have to be put into master as a result of that merge.
    – eftshift0
    May 31, 2021 at 19:52
  • The common ancestor is the last common commit where the file is the same in both branches? so when i did a merge of master into branch did the last common commit change for the file?
    – user993797
    May 31, 2021 at 19:59
  • 2
    Your diagrams are inconsistent and make no sense and there is no m3. Please fix the diagrams to clarify the question. Thanks.
    – matt
    May 31, 2021 at 21:00
  • See also this question and this one as well. The lack of a conflict after merging is a result of the updated merge base, as matt answers.
    – torek
    Jun 1, 2021 at 0:31

1 Answer 1

2

Thing to know: what is a merge? It is a combination of the changes in both branches since the merge base (ie where the branches "diverged" most recently).

"what tells git that the one in branch is the 'right' one."

That is the whole point of "reverse" merges. Imagine this situation:

 mergebase
     |
A -- B -- C <- master
     \
      X <- branch

At this moment, B is the merge base if you merge either way between the two branches. Assume that both C and X change the same file in such a way as to generate a potential merge conflict. OK, so you merge master into branch and fix the conflict in that file (forming merge commit M in the diagram below). This also moves the merge base to the tip of master (C), in preparation for the upcoming forward merge:

      mergebase
          |
A -- B -- C <- master
     \    \
      X -- M <- branch

Hopefully, when you do then merge branch into master, master is unchanged since the merge base C (at least with respect to this file). Thus master makes no contribution since the merge base, but branch does (the merge commit M has a different version of the file than C does), so only branch contributes to the merge and its version of the file is adopted.

1
  • That makes sense, I did not realize that an activity in the branch ( a merge) would also further the merge base on the source branch ( master). Thanks for taking the time.
    – user993797
    Jun 1, 2021 at 3:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.