How to Undo Anything in Git — Reset, Revert, Restore

Complete guide to undoing changes in Git: reset, revert, restore, amend, reflog. Fix mistakes confidently.

Undo Unstaged Changes

# Discard changes in a specific file
git restore file.js

# Discard ALL unstaged changes
git restore .

Undo Staged Changes

# Unstage a file (keep changes in working dir)
git restore --staged file.js

# Unstage everything
git restore --staged .

Undo Last Commit

# Undo commit, keep changes staged
git reset --soft HEAD~1

# Undo commit, unstage changes
git reset HEAD~1

# Undo commit AND discard changes (DANGEROUS)
git reset --hard HEAD~1

Fix Last Commit Message

git commit --amend -m "new message"

Undo a Push

# Create a new commit that undoes the bad one (SAFE)
git revert <commit-hash>
git push

# Force push to remove commit (DANGEROUS on shared branches)
git reset --hard HEAD~1
git push --force-with-lease

Recover Lost Commits with Reflog

# View reflog — shows ALL recent actions
git reflog

# Restore to a specific point
git reset --hard HEAD@{3}

Decision Tree

SituationCommand
Discard local file changesgit restore <file>
Unstage a filegit restore --staged <file>
Undo last commit (keep changes)git reset --soft HEAD~1
Undo pushed commit safelygit revert <hash>
Fix commit messagegit commit --amend
Find lost commitgit reflog

Need These Tools as an API?

TextForge API offers 20+ developer toolkit endpoints. Free tier: 50 requests/day.

Try TextForge API Free →

Related Tools