Theory
Theory: Rebase Copies Commits; It Does Not Slide Them
A rebase walks a range of commits, takes each patch against its parent, and applies it onto a new base. Each successful apply writes a new commit (new hash, usually same author, you as committer).
Invariants
- Original commits remain in the object store until GC; the branch name moves to the copied tip.
- Conflicts happen once per copied commit, not once at a join.
- Interactive rebase is the same machine plus a todo list (
pick,squash,fixup,reword,edit,drop). pull --rebase= fetch + rebase local-only commits onto@{u}.--ontois “take this range and replay it on that commit,” the general form of rebase.
before after git rebase main
A ← B ← C ← G main A ← B ← C ← G main
↑ ↖
D ← E feat D' ← E' feat
Why teams fight about it
Merge preserves hashes and adds a node. Rebase rewrites hashes and can keep main linear. Unpublished feature branches are the safe audience. Published main is not.
What can break
- Rebasing commits other people have based work on (force-push incident).
--ours/--theirsconfusion vs merge.- Empty commits after rebase (
--skipvs keep).
How to read this chapter
Why, interactive, conflicts, pull –rebase, vs merge, lab; then --onto, autosquash, --exec, --update-refs.