Skip to content
IT glossary
ProgrammingUpdated December 3, 2026

Squash

In Git, squashing combines several commits into one. The new commit records their net effect without keeping each intermediate step in that branch’s history.

Also known as: сквош, squash commits

What squashing does

A feature branch can tell the story of how you worked: add CSV export, correct the header row, then add tests. Someone reading the main branch later may only need to know what shipped. Squashing turns those three commits into a single Add CSV export commit that includes the corrected headers and tests.

Two ways to squash

  • Rewrite commits on a branch. An interactive rebase can replace several consecutive commits with one. If you squash them in place without changing their base, the combined commit has the same parent as the first commit and the same file snapshot as the last. It gets a new commit ID, and the branch no longer lists the original commits in its history.
  • Squash when integrating a pull request. A squash merge puts the integrated changes into one new commit on the target branch and leaves the source branch untouched. This is not a two-parent merge commit: Git does not record the source commits as ancestors of the new commit. On the command line, git merge --squash feature prepares the result on the current branch; you still need to run git commit to record it.

Example: clean up a local feature branch

Suppose the last three commits on your branch form a straight line and your working tree is clean. Run git rebase -i HEAD~3. The editor lists the oldest commit first. Keep pick on that first line and change the next two to squash:

pick a1b2c3d Add CSV export
squash b2c3d4e Correct the header row
squash c3d4e5f Test CSV export

After you save the list, Git lets you write a message for the combined commit. If you want to fold in a commit's changes without bringing along its message, use fixup instead. Check the result with git log --oneline: where the branch used to show three commits, it should now show one.

When to keep commits separate

Squash work-in-progress commits when they all belong to one change that reviewers or maintainers would want to understand and revert as a unit. Keep independent changes separate. If an export feature also includes an unrelated refactor, combining them makes it harder to revert just the feature. It also means git bisect on that branch can no longer test the intermediate snapshots inside the combined commit.

Avoid rewriting a shared branch without coordinating with anyone who may have based work on it. If you already pushed your feature branch and the team agrees to update its history, prefer git push --force-with-lease over --force: it checks that the remote branch is at the commit you expect before overwriting it.

Interview angle

You may be asked why Git can still treat a feature branch's commits as unmerged after a squash merge. The target branch contains their combined effect, but it does not contain those commits in its ancestry. In Git, having the same changes is not the same as sharing the same history.