Tagged as: git linux

Sometimes, you just don't get it right the first time, and you need to undo your last commit. Perhaps you accidentally added files you didn't want to, or just want a clean slate.

Luckily, your problem is easy to fix. Simply run this command:

git reset --soft HEAD~

This will reset your repository to the moment before you committed. If you want to remove all the files that were staged as well, you can:

git reset HEAD~

Simply make the changes you needed, add your files, and commit again.

If you want to change an existing commit rather than undo it, you can use git --amend: How to Edit the last git Comment