I’m trying to understand the difference between a squash and a rebase. As I understand it, one performs a squash when doing a rebase.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Both
git merge --squashandgit rebase --interactivecan produce a "squashed" commit. But they serve different purposes.git merge --squash abranchwill produce a squashed commit on the destination branch, without marking any merge relationship.
(Note: it does not produce a commit right away: you need an additional
git commit -m "squash branch")This is useful if you want to throw away the source branch completely, going from (schema taken from SO question):
to:
and then deleting
tmpbranch.Note:
git mergehas a--commitoption, but it cannot be used with--squash. It was never possible to use--commitand--squashtogether.Since Git 2.22.1 (Q3 2019), this incompatibility is made explicit:
See commit 1d14d0c (24 May 2019) by Vishal Verma (
reloadbrain).(Merged by Junio C Hamano —
gitster— in commit 33f2790, 25 Jul 2019)git/gitbuiltin/merge.c#cmd_merge()now includes:git rebase --interactivereplays 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:
If you choose to squash all commits of
tmp(but, contrary tomerge --squash, you can choose to replay some, and squashing others).So the differences are:
squashdoes not touch your source branch (tmphere) and creates a single commit where you want.rebaseallows you to go on on the same source branch (stilltmp) with: