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 →
git rebase -i HEAD~3, mark the commitedit.git reset HEAD^to unstage it, leaving changes in the tree.git add -pto stage the refactor hunks, commit, then stage and commit the fix.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.
More on Undoing Mistakes
You committed on `main` when you meant to be on a feature branch. Nothing is pushed. Fix it.BeginnerYou made a typo in your last commit message and have not pushed.BeginnerA bad commit is already on shared `main`. Others have pulled it. How do you undo it?IntermediateYou ran `git reset --hard` and lost uncommitted-then-committed work. Can you get it back?IntermediateYou need to revert a merge commit on `main`. `git revert` says "commit is a merge but no -m option was given".IntermediateYou deleted a local branch with unmerged work by mistake.Beginner