Interview Prep/Git & GitHub/Undoing Mistakes

You edited a file with a debug print and a real fix. You want to commit only the fix.

BeginnerScenarioUndoing Mistakes
Answer

Situation read → Two changes live in one file.

What I'd do →

  1. git add -p file.py.
  2. Answer y to the fix hunk, n to the debug hunk, s to split a hunk, e to edit it by hand.
  3. git diff --staged to verify, then commit.
  4. Remove the debug line afterwards.

Why → Patch mode stages hunks, not whole files, so commits stay focused.

Interview tip → Mention git commit -p as a shortcut.

All Git & GitHub questions Roadmap: Git & GitHub

More on Undoing Mistakes