DEV Community

Jaweher Ben Salah
Jaweher Ben Salah

Posted on

Answer: How do I undo the most recent local commits in Git?

A simple step-by-step guide is as follows:

  • Destroy a commit and throw away any uncommitted changes

    git reset --hard HEAD~1
    
  • Undo the commit, but keep your changes

    git reset HEAD~1
    
  • Keep your files, and stage all changes back automatically

    git reset --soft HEAD~1
    
  • Resurrect a commit you destroyed

    git reflog

Top comments (0)