Practice: Undo Challenges
Choose the right undo.
You now know many ways to undo things. The hard part is choosing the right one. Here are four situations. For each one, pause, and decide which command you'd use.

- Many ways to undo
- Choosing is the hard part
- Four situations
Which undo?
Situation one. You edited a file, and want the last committed version back. Use git restore. Situation two. You staged a file by mistake. Git restore dash dash staged. Situation three. Your last commit has a typo, and isn't pushed. Git commit dash dash amend. Situation four. A pushed commit broke main. Git revert.
| Situation | Command |
|---|---|
| Undo edits to a file | git restore <file> |
| Unstage a file | git restore --staged <file> |
| Fix the last commit, not pushed | git commit --amend |
| Undo a pushed commit | git revert <hash> |
Situation four, for real
Let's do situation four for real. The latest commit, broken layout, made the page invisible. It's already on GitHub, so we revert it. Git creates the undo commit, and we push it. Main is fixed, and nobody's history was rewritten.
git log --oneline -n 2 e8cffdc (HEAD -> main, origin/main) Broken layout f63a17a Link to about page git revert --no-edit HEAD [main 7fbe649] Revert "Broken layout" Date: Mon Jan 5 09:41:06 2026 +0000 1 file changed, 1 deletion(-) git push To https://github.com/sam/my-site.git e8cffdc..7fbe649 main -> main
Summary
Restore for edits, restore staged for staging, amend for the last private commit, revert for shared commits. Next, the most powerful idea in Git. Branches.
Key takeaways- Edits: restore
- Last private commit: amend
- Shared commit: revert