To undo a recent commit use the following commands.
If you want to keep your changes (Changes will return to working directory):
git reset HEAD~
If you want to keep your changes (Changes will return to staging):
git reset --soft HEAD^
if you don't want to keep the changes (All changes made in the commit will be deleted from staging and the working directory):
git reset --hard HEAD^