Skip to content
Scatlion
Web Development

How to squash a commit

Sometimes we might commit some sensitive data, this is a way to undo this before pushing it to the Github repository

1 min read

If you just messed up your last commit (wrong message, forgot to add some changes) and want to fix it before pushing it to a public repo why not use:

TEXT
git commit --amend -m "New message here"

If you have newly staged changes they'll be combined with the last commit (that you're trying to get rid of) and will replace that commit.

Of course if you amend a commit after you've pushed it, you're rewriting history so if you do that be sure to understand the implications.

You can also pass the '--no-edit' option instead of '-m' if you would prefer to use the previous commit's message.

Docs: http://git-scm.com/docs/git-commit.html