Undo last Git commit using git undo-commit command

There are probably thousands of websites telling you, how to undo the last Git commit. For example, one of the most voted up questions on Stack Overflow. But none of them (or actually nearly none of them) answers, how to do this using git undo-commit. Simply because, such command does not exist! :> Therefore, the title of this text should rather sound “Defining own Git alias to undo last Git commit“, since this article is focused on git aliases rather than on undoing last commit in Git.

This is quick-by-example and keep-me-in-memory article. An answer to the question, how to define own Git alias to undo last git commit, you’ll find among comments to question mentioned in previous chapter. It is really as easy as:

git config --global alias.undo-commit 'reset --soft HEAD^'

And then you can type just git undo-commit to roll back last commit as needed.

That’s all folks! Thank you, RecursivelyIronic, for this tip.

Leave a Reply