Why do you need a common ancestor when merging Git?

Asked 2 years ago, Updated 2 years ago, 44 views

This article mentioned the following:

We merged the two snapshots pointed to by each branch and their common ancestors in three directions.

What I'm not sure about here is why we need a "common ancestor" to merge.
I thought it would be enough to merge the last commits of the two branches, but where do I need a common ancestor?It's amazing.

git

2022-09-30 16:26

1 Answers

For example, suppose you changed the file hoge.txt to two branches, respectively:

hoge.txt

on branchA
A
hoge
B
C

hoge.txt

in branchB
A
B
piyo
C

Try merging these two.Can you do it?

Which of the following merge results should I choose?

  • Right to include both hoge and piyo which were not originally present
  • "Deleted hoge and piyo respectively" is correct not to include either
  • "Actually, branchA has not changed anything" branchB is correct
  • "Actually, branchB has not changed anything" branchA is correct
  • What about B that was added in both B was not even there
  • in the first place?
  • etc...

To determine this, you need the information How did each change to a common ancestor

?


2022-09-30 16:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.