Undo, recovery, and reflog
Choose recovery based on whether work is committed or shared.
- Difficulty
- beginner
- Time
- 45 minutes
- Last verified
- 9/21/2026
What you will build
Choose recovery based on whether work is committed or shared.
Understand the idea first
Choose recovery based on whether work is committed or shared.
Build it step by step
git restore path/to/file
git restore --staged path/to/file
git revert <shared-commit>
git reflog- Open the previous project and record its result.
- Type the example and complete: Restore an unstaged file, unstage one, and revert a shared commit.
- Change one input, predict, then verify.
- Create and repair: Do not hard-reset or force-push shared history casually.
Read the important lines
- Choose recovery based on whether work is committed or shared.
- Read input, processing, and output separately.
- Verify another input and an edge case.
Common mistakes and what to check
| Symptom | What to check |
|---|---|
| Unexpected result | Do not hard-reset or force-push shared history casually. |
| Nothing changes | Save, verify paths, and read the first relevant Console error. |
Practice without copying
Restore an unstaged file, unstage one, and revert a shared commit.
Check the answer after you try
Rebuild and explain the decisions. Check: Do not hard-reset or force-push shared history casually.
Completion check
- I produced the required visible result
- I can explain the input, processing, and output
- I tested normal, edge, and failure cases