Get "PHP 8 in a Nuthshell" (Now with PHP 8.4)
Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

Git Uncommit

Here’s a handy little Git alias that you can use to undo your last commit. Thanks to Freek sharing this on X.

git config --global alias.uncommit 'reset --soft HEAD~1'

This will create a global Git alias called uncommit that reverts the current repository’s last commit using soft reset and puts the changes back into the staging area.

So, if you want to undo your last commit, you can do it like so.

git uncommit

Bonus: While you’re here, you can list down all the Git aliases you have created using the following command.

git config --list | grep alias

See ya.

👋 Hi there! I'm Amit. I write articles about all things web development. If you enjoy my work (the articles, the open-source projects, my general demeanour... anything really), consider leaving a tip & supporting the site. Your support is incredibly appreciated!

Comments?