During review you get ten small change requests on old commits. How do you apply them cleanly?
IntermediateScenarioRebase, Cherry-pick and History Rewriting
Answer
Situation read → You want fixes folded into the right commits, not a pile of "address review" commits.
What I'd do →
- For each fix:
git add -p && git commit --fixup <target-sha>. - When done:
git rebase -i --autosquash origin/main. - Enable permanently:
git config --global rebase.autoSquash true. - Push with
--force-with-lease; mention it in the PR so reviewers re-check.
Why → Fixup commits are auto-ordered and squashed, so history reads as if the code was right the first time.
Interview tip → Some teams prefer review fixup commits until approval to ease re-review. Know both.
More on Rebase, Cherry-pick and History Rewriting
Your PR branch has ten commits like "wip", "fix typo", "oops". How do you clean it up before review?BeginnerYou want the database migration commit to come before the code that uses it.BeginnerA critical fix on `main` must go to the `release/4.1` branch only.BeginnerYou must backport a feature made of 6 commits, including one merge commit.IntermediateBranch B was built on top of branch A. A was squash-merged into `main`, and now B shows A's commits again.IntermediateDuring a rebase, "ours" and "theirs" seem backwards. Why?Intermediate