(Interactive) rebasing technically squashes only two commits at a time—simply because the so-called "rebase script" you're typically asked to edit before git rebase
proceeds applies an action to a single commit at a time.
This does not, however, change the outcome because logically there's no difference between squashing N commits at once or doing this commit-by-commit.
In your rebase script, you just pick the action "squash" (also read up on "fixup"—it's often may be more handy than "squash") for a series of adjacent commits, and then git rebase
works like this:
- Get the commit marked "squash". Squash it to the previous commit—effectively re-writiing that with the new content applied to it (as with
git apply
).
- Given that new state, go to step 1. ;-)
Note that there's also the --squash
command-line option of git merge
.
This one squashes several commits at once for real.