There are 3 combinations of git strategies, one is Resovle, one is recursive, and the other is octopus. Where resolve and recursive apply to merging 2 Branch,octopus for merging 3 or more than 3 branch. For these 3 strategies, it is necessary to involve merge-base commit,ours commit and theirs commit, which is 3-way mege.
3-way Merge
As shown, if you want to merge branch B into branch A, then branch A's tip commit is ours commit,branch B's tip commit is theirs commit, and two branch public commit ( The shadow commit in the diagram is merge-base. When merging, the change of theirs commit relative to the Merge-base commit is applied to the ours commit, and a new commit is generated.
However, if the theirs commit changes with respect to the Merge-base commit, in the same region, the ours commit changes relative to the Merge-base commit, which creates a conflict. For example, Merge-base commit, ours commit,theirs commit has the same file a as shown:
Theirs commit's change from merge-base commit is to modify the 2 between 1 and 3 to 5, while ours commit has been modified between 1 and 3 in relation to Merge-base commit, that is, 8 is inserted, so a conflict occurs when merging:
1
++<<<<<<<<<ours
+2
+8
++=========
+ 5
++>>>>>>>>theirs
3
+4
At the same time as the conflict, Git will record merge-base commit,ours Commit,theris commit file in index, and it can be viewed by the git ls-files-u command.
Merge-base
Merge-base is the best common ancestor between branch. Common ancestor A is more than the other common ancestor B better condition is: B is the ancestor of a. Therefore, a best common ancestor does not have any better common ancestor. For example, as shown in:
There are two best common ancestor between branch A and branch B, which is the shadowed commit 1 and commit 2 in the diagram. Another example:
At this point, the best common ancestor of branch A and branch B are shaded commit 3 instead of commit 1 and Comit 2 because commit 3 is ancestor of commit 1 and commit 2.
Using git merge-base--all can find out all the best common ancestor.
Recursive strategy
The recursive strategy of merge is that when there are multiple best common ancestor between the two branch, git merges these best common ancestor in a temporary way, The temporary commit is then combined as a merge-base to merge the branch. If there is a conflict, Git will still record in index, or it can be viewed through the git ls-files-u command.
Git merge's recursive strategy and Merge-base