Last Updated: July 25, 2019
·
18.79K
· toreriklinnerud

git merge --squash

This git --squash flag doesn't seem to get much attention. It allows you to merge all changes on a branch into your current branch, but as a single commit. Squashing to a single commit gives you an opportunity to clean up messy WIP commits and provide a good rationale for the changes your are merging.

When you know that you are going to squash anyway, there is nothing that stops you from committing left, right and center on your feature branch, with broken tests and whatever. Liberating!

3 Responses
Add your response

interesting, but keep it mind that squashing many commits into one can make things a bit heavy if there is a lot of commits / lines.

it's a powerful tool so big responsibility comes with it !

over 1 year ago ·

I like "git rebase -i" (interactive) You're prompted with a list of commits, and you can cherry pick right there, which ones to squash and which to keep. Even getting a chance to modify the commit messages. A great way to clean up a bunch of ugly commits into a few clean ones. Even if that means in the end you just squash it all into one commit, as --squash would have done.

There must be a way to get the same behavior while doing a classic merge instead of a rebase.

over 1 year ago ·