Last Updated: February 25, 2016
·
1.418K
· errm

Squash some commits

So as your working on a branch its a v.good idea to commit often to keep track of what you have done, but before you push to master you may well want to clean things up and squash some commits.

git rebase -i HEAD~5

where 5 is the number of commits you want to squash, as its interactive you can reorder your commits, change the commit messages, squash some commits and keep others. Just make sure you have your editor setup properly.

6 Responses
Add your response

git rebase -i master

This will show you all of the commits on your feature branch and allow you to pick and squash any of them.

over 1 year ago ·

@paulyoung awesome. Even better

over 1 year ago ·

@paulyoung one for the aliases

over 1 year ago ·

And in case you want to undo a rebase:

git reflog
git reset --hard <last_commit_before_rebase>
over 1 year ago ·

@eskimoblood Wow looks cool

over 1 year ago ·