A
cd ..
Git

Git Undo Cheat Sheet

How to undo mistakes in Git at various stages.

2025-08-22
git, version-control

Undo 'git add'

Unstage a file but keep changes in working directory.

git reset HEAD <file>

Undo local changes (Discard file)

Revert file to state in last commit.

git checkout -- <file>

Undo last commit (Keep changes)

Soft reset moves HEAD back one step but keeps changes staged.

git reset --soft HEAD~1

Undo last commit (Discard changes)

Hard reset moves HEAD back and deletes changes. Dangerous.

git reset --hard HEAD~1

Change last commit message

git commit --amend -m "New message"

Was this useful?

Share with your team

Browse More