How do I undo the last git commit?

Ask Question
Asked 13 hours agoViewed 2.3k times
31

I committed too early and want the changes back in my working tree without losing them.

PN
asked 13 hours agoPriya Nair6,386

2 Answers

  • Accepted answer

    git reset --soft HEAD~1 keeps your changes staged so you can re-commit them cleanly.

    SA
    answered 12 hours agoSofia Alvarez5,306
  • For shared history, prefer git revert so you do not rewrite commits other people already pulled.

    LO
    answered 12 hours agoLiam OConnor2,940

Your Answer