Overview
Undo operations are high-risk when their scope is misunderstood.
The safest question is not "How do I undo this?" but "Which state should be preserved?"
- Preserve file edits but remove them from staging: git reset or git restore --staged.
- Discard uncommitted file edits: git restore.
- Restore committed files and discard all current local changes: git reset --hard.
- Delete and stage a tracked file: git rm.
- Stop tracking but keep the local file: git rm --cached.
- Correct a committed mistake while preserving a traceable history: git revert.
- Remove the latest commit and return its changes to active work: git reset HEAD^.
This decision framing prevents a destructive command from being used when a reversible one would be sufficient.