Why is tripartite merging required to restart git?

I am trying to understand why rebase requires a three-way merge. For example, if we have

A1 - A2 \ B1 

And I checked B1 and I want to execute:

 git rebase A2 

why git merge A2, B1 AND A1? Why would A2 and B1 not be enough? I mean, not A2 and B1 how commit contain the full current snapshot of the tree?

+7
source share
1 answer

To perform a merge, Git needs to figure out what exactly happened in two branches from a common ancestor ( A1 ). As you said correctly, Git stores snapshots of commits / trees in order to get the actual set of changes, it has to compare A2 with A1 and B1 with A1 , and then combine these separate sets of changes.

The same thing happens in rebase. To apply change set A2 to B1 , we first need to calculate that the change is set from the differences between A1 and A2 . And then we can apply this to B1 . You can think of rebase as something like automatically creating patch files. First, it generates all these patch files from the old branch and applies them to the current HEAD.

So, we need all these three commits in order to actually calculate the differences, since we cannot understand what happened in the commit just by looking at this message.

+7
source

All Articles