How to Undo a GIT Commit

Understand the basics of version control

Redin Gaetan
1 min readSep 8, 2021

Hey, I’m sure I’m not in this case. You know you make your git add <files>and then your git commit -m "..." But oh no I forgot a file… Well rather than create a second commit, why not just undo the previous one and recreate it?

Here’s a git alias I use every day:

alias.undo=reset --soft HEAD^

Here’s how to create it:

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

Tips: If you have already pushed your commit into your PR, you will have to use git push -f .

Thanks for reading.

--

--