From time to time I stumble upon a statement that 'git rebase' leads to a fewer number of conflicts than 'git merge', for example here: Why does git rebase often have fewer merge conflicts than a merge?. Does it mean that there may be situations where git-merge <BRANCH_A> <BRANCH_B>
would fail, I would do git reset --hard ORIG_HEAD
, then do git-rebase <BRANCH_B> <BRANCH_A>
and it would succeed? Can you give me an example of such situation?
Imagine a history like this:
A-B-C-D-E “top-branch”
\
F-G-H
Now merging E
into H
means: “take a diff of B‣H
and a diff of B‣E
and find out how to combine them”.
Rebasing on the other hand means:
B‣F
and a diff of B‣E
and find out how to combine them into F’
F‣G
and a diff of F‣F’
and find out how to combine them into G’
G‣H
and a diff of G‣G’
and find out how to combine them into H’
So rebasing is exactly the same as merging F
, then G
and then H
into top-branch
.
The rebase method will do the merge in way more steps. This has advantages and disadvantages.
H
is actually a revert of F
.In my opinion rebase is actually the worse process and while that might be possible I am having trouble imagining a situation where it actually avoids conflicts. What seems quite likely is that you have a conflict that is only caused by a one-line change in F
. When that codeblock is further changed in G
, you might have to resolve all of these changes as one conflict in a merge, but you only have to resolve that one-line change in a rebase. But that is not really a difference, as the conflict will only look bigger, but should be just as easy to resolve.