Skip to content

Git Undo Cheat Sheet

| reference

I always forget which command does what.

Unstage a file (undo git add)

git restore --staged <file>

Discard local changes (undo edits)

⚠️ Destructive

git restore <file>

Amend the last commit (fix typo/add file)

git commit --amend --no-edit

Undo last commit (keep changes staged)

git reset --soft HEAD~1

Undo last commit (keep changes unstaged)

git reset HEAD~1

Throw away everything (nuclear option)

git reset --hard HEAD