You have a 60-commit branch full of experiments and need a reviewable PR.
IntermediateScenarioRebase, Cherry-pick and History Rewriting
Answer
Situation read → The final tree is good but the history is unreadable.
What I'd do →
- Keep a backup:
git branch experiment-backup. git reset --soft $(git merge-base origin/main HEAD)collapses everything into staged changes.- Re-commit in logical pieces using
git add -p: schema, core logic, API, tests, docs. - Force-push the cleaned branch.
Why → You build the story you want reviewers to follow, with tests passing at each step.
Interview tip → Alternatively, offer several smaller PRs. Reviewers handle those much better.
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 review you get ten small change requests on old commits. How do you apply them cleanly?Intermediate