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
  1. Open the previous project and record its result.
  2. Type the example and complete: Restore an unstaged file, unstage one, and revert a shared commit.
  3. Change one input, predict, then verify.
  4. 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

SymptomWhat to check
Unexpected resultDo not hard-reset or force-push shared history casually.
Nothing changesSave, 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

Your privacy choices

Necessary storage is always on. Optional analytics and support services load only after consent.