Interview Prep/Git & GitHub/Undoing Mistakes

You ran `git add .` and staged a file you didn't want to commit.

BeginnerScenarioUndoing Mistakes
Answer

Situation read → Only the index is wrong; the working file is fine.

What I'd do →

  1. git restore --staged secrets.env unstages it and keeps your edits.
  2. Add it to .gitignore if it must never be committed.
  3. git status to confirm.

Why → restore --staged copies HEAD's version into the index. On older Git, git reset HEAD file does the same.

Interview tip → Review with git diff --staged before every commit.

All Git & GitHub questions Roadmap: Git & GitHub

More on Undoing Mistakes