Interview Prep/Git & GitHub/Undoing Mistakes

One commit mixes a refactor and a bug fix. Reviewers want them split.

IntermediateScenarioUndoing Mistakes
Answer

Situation read → You need two commits from one, with hunks assigned correctly.

What I'd do →

  1. git rebase -i HEAD~3, mark the commit edit.
  2. git reset HEAD^ to unstage it, leaving changes in the tree.
  3. git add -p to stage the refactor hunks, commit, then stage and commit the fix.
  4. git rebase --continue.

Why → Mixed reset keeps the changes but drops the commit, letting you recommit selectively.

Interview tip → Small, single-purpose commits make bisect and revert far cheaper.

All Git & GitHub questions Roadmap: Git & GitHub

More on Undoing Mistakes