To undo the last commit, discarding the changes:

git reset --hard HEAD~1

To undo the last commit, keeping the changes:

git reset HEAD^
OR
git reset --soft HEAD~1