DEV Community

StuartCreed
StuartCreed

Posted on • Edited on

How to undo a git commit

Most of the time you just need to delete the last commit because you haven't had enough coffee and have made a mistake! - we are human! To do this run:
git reset --hard master~1

Notes on this:

  • This will also delete the changes in the files associated to this last commit
  • You can replace master with any branch you want.
  • Change 1 to a different number to remove more commits on that branch

To specify a certain commit e.g.:
git reset --hard 0ad5a7a6

If you run it with the soft tag it will not delete the files in the directory:
git reset --soft master~1

Top comments (0)