Undo Your Last Commit in Git 🔙
Made a mistake? Learn how to step back safely using Git Reset.
We've all been there: you typed git commit, hit enter, and immediately realized you forgot a file or made a typo. Don't panic! You can easily undo that commit.
Option 1: The Soft Reset (Safe)
Use this if you want to undo the commit action but keep your file changes. Your work will move back to the 'Staged' area.
git reset --soft HEAD~1Option 2: The Hard Reset (Destructive)
⚠️ Warning: Use this only if you want to completely destroy the commit and delete all changes in it. There is no going back.
git reset --hard HEAD~1Summary
Use --soft to fix a mistake and commit again.
Use --hard to trash the work entirely.
HEAD~1 simply means 'go back 1 commit'.