How to merge all your history

Ali Zhagparov
Javarevisited
Published in
Oct 17, 2021

--

Sometimes it may happen that you created too many commits, and it will be better if you squash them into 1.

In git, we don’t have a squash command; instead, you can use a git rebase with an additional interactive flag.

For instance, our branches look like that.

To make proper squash, you need to specify commit you will start from

  1. git squash with setting commit hash

git rebase --interactive fca43bdf851c5da090e873c8573c28108e0c1b9c

2. git squash with specifying commit HEAD

git rebase --interactive HEAD~3

if we want to squash commit, just change pick to s or squash then save it. After that, you need to set the commit message like that :

then just save it, after that you need to specify the commit message

like that

At the end of rebase operation, you will get the following result.

--

--