I'm new to git and I'm trying to understand the difference between a squash and a rebase. As I understand it you perform a squash when doing a rebase.
git merge --squash and
git rebase --interactive can produce a "squashed" commit.
But they serve different purposes.
will produce a squashed commit on the destination branch, without marking any merge relationship.
This is useful if you want to throw away the source branch completely, going from (schema taken from SO question):
git checkout stable X stable / a---b---c---d---e---f---g tmp
git merge --squash -m "squash tmp" tmp X-------------------G stable / a---b---c---d---e---f---g tmp
and then deleting
replays some or all of your commits on a new base, allowing you to squash (or more recently "fix up", see this SO question), going directly to:
git checkout tmp git rebase -i stable stable X-------------------G tmp / a---b
If you choose to squash all commits of
tmp (but, contrary to
merge --squash, you can choose to replay some, and squashing others).
So the differences are:
mergedoes not touch your source branch (
tmphere) and creates a single commit where you want.
rebaseallows you to go on on the same source branch (still