Interview Prep/Git & GitHub/Undoing Mistakes

You want to discard local edits to one file and go back to the last commit.

BeginnerScenarioUndoing Mistakes
Answer

Situation read → Working tree changes are unwanted.

What I'd do →

  1. git restore path/to/file, or git restore . for everything.
  2. For untracked files, preview first: git clean -nd, then git clean -fd.

Why → These changes were never committed, so this cannot be undone. Hence preview with -n.

Interview tip → Mention that git stash is the non-destructive alternative if you are unsure.

All Git & GitHub questions Roadmap: Git & GitHub

More on Undoing Mistakes