How to undo the last Git commit?

undo the last Git commit

Undoing a commit seems little difficult if you don’t know how to do it. But it’s actually pretty simple, here is simple commands for Undo a commit and redo

  1. $ git commit – This is what you want to undo
  2. $ git reset –soft HEAD^ – This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both. Leaves working tree as it was before “reset”.
  3. $ edit – Make corrections to working tree files.
  4. $ git add – Stage changes for commit.
  5. $ git commit -c ORIG_HEAD – “reset” copies the old head to .git/ORIG_HEAD; redo the commit by starting with its log message. If you do not need to edit the message further, you can give -C option instead.

Leave a Reply