by rtpg · 2y ago · 0 comments
http://bryan-murdock.blogspot.com/2022/12/git-rebase-explain...
Rebase is really a merge (actually one merge per commit you are rebasing). At least it should be. With mercurial it really seems to be. With git I'm not so sure because it feels like it's always worse at resolving conflicts than mercurial. I haven't tested it thoroughly or looked at the implementations
And even then, when using rebase to "resync" different branches, I don't think it's accurate to characterize it as a merge at all. It's a hard reset plus a series of cherry-picks.
(As an aside, this is why rebase can be much more annoying than a merge! Merging a branch onto another is usually quick and easy. Git's merge algorithms usually do a decent job of figuring out how to do a merge without conflicts. And if there are conflicts, you only have to resolve them once. If instead you rebase, you may have to resolve the same (or similar) conflicts over and over and over, once for each cherry-pick. And there might be conflicts that wouldn't have even occurred with a simple merge. Git's rerere mechanism does automate some of it, sometimes, though.)
In the case of multiple commits, it has to perform a merge operation for each of those commits, that's why you end up seeing the same merge conflicts over and over.
For interactive rebase, there are so many scenarios there that it would probably take a few posts to explore them all.
I'll look for her post about rebase, it sounds interesting, thanks!
def rebase(base, curr=HEAD):
common_ancestor = git_merge_base(base, curr)
git_checkout(common_ancestor)
for commit in commit_range(common_ancestor, curr):
git_cherry_pick(commit)
Does that help?