Squashing multiple commits into one

In your daily tasks if you need to squash multiple commits into one with a custom message just perform the following commands:

git reset --soft HEAD~n # where n is the number of last commits you want to squash into one

git commit --amend

git push -f

another (interactive) way is to use rebase like below:

git rebase -i HEAD~n

the last n commit messages will appear in your text editor. You will see something similar to:

pick 0123456 Message 1
pick 1234567 Message 2
pick 2345678 Message 3

you could just pick the first commit and squash the rest like that:

p 0123456 Message 1
s 1234567 Message 2
s 2345678 Message 3

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.