You made four messy "wip" commits locally. You want a single clean commit before pushing.
IntermediateScenarioUndoing Mistakes
Answer
Situation read → Local, unpushed history can be collapsed.
What I'd do →
git reset --soft HEAD~4moves the branch back but leaves all changes staged.git commit -m "Add retry logic to payment client".- Alternative:
git rebase -i HEAD~4and mark later commitssquashorfixup.
Why → Soft reset only moves the branch pointer; index and working tree stay as they are.
Interview tip → git commit --fixup <sha> plus git rebase -i --autosquash is the polished workflow.
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