git commit --amend
The command amend
changes the latest commit by replacing with the new one. Suppose you have changes in working directory, by running git commit --amend
the new changes will be committed as replacement of the old latest commit. If there is no new changes, this command will let you change commit comment of the latest commit and save as new commit replacing old latest commit.
# undo commit
git reset --soft HEAD~1
# undo add