How to undo the last commit in Git?

Some issues happen in your last commit and you'd like to undo it to revert your git branch to previous version. You just use the reset command with the command options:

$ git reset --hard HEAD~1
$ git push -f

- The --hard option clear all changes of the last commit. Be sure when do it, because after that, your changes in the last commit will be lost.
- Use HEAD~1 to return to the one before the current revision (last commit)

Either, if you'd like to keep your changes in the last commit for local modifications, let use --soft option instead --hard:

$ git reset --soft HEAD~1

© 2019 4codev

Created with love by Sil.