← Back to Blog

Git Undo Last Commit: 5 Ways to Fix Mistakes

How to undo the last git commit: soft reset, mixed reset, hard reset, revert, and amend. Know which one to use and when.

5 Ways to Undo

// 1. Undo commit, keep changes staged\ngit reset --soft HEAD~1\n\n// 2. Undo commit, keep changes unstaged\ngit reset HEAD~1\n\n// 3. Undo commit AND discard changes (DESTRUCTIVE)\ngit reset --hard HEAD~1\n\n// 4. Undo a pushed commit (safe for shared branches)\ngit revert HEAD\n\n// 5. Fix the last commit message or add files\ngit commit --amend

Try It Free

Use our free online tool — 100% client-side, no data leaves your browser.

Open .gitignore Generator

Related Tools & Articles