DEV Community

ajay upreti
ajay upreti

Posted on

How to Squash 3 commits into 1?

Do git log and see the commits you want to squash is commited first.

if you want squash top 3 commits from your head,
Use this command,

git rebase -i HEAD~3

Here the tilde ~ symbol with 3 pick the top latest three commits and it will pop up in an interactive shell where you can select the top commit and squash other two commits into one by entering s, it means squash.

If your commit is not appearing then do git log and see, if not then

git add files
git commit -m 'your commit'

Top comments (2)

Collapse
 
kigster profile image
Konstantin Gredeskoul

Or, install Bashmatic:

bash -c "$(curl -fsSL https://bashmatic.re1.re); bashmatic-install -q"
source ~/.bashmatic/init.bash

# and use git.squash function:
git.squash 3
Enter fullscreen mode Exit fullscreen mode
Collapse
 
kigster profile image
Konstantin Gredeskoul

Blog post coming on Bashmatic.... see kig.re/