WEEK 7 · LESSON 5 · TOPIC 3 OF 6 · Why It Matters

Why It Matters

Lesson progress

0% Complete

SECTION 1 OF 1

In this topic · 1 sections
  1. Overview

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.