You want to rebase a branch that contains merge commits without flattening them.
AdvancedScenarioRebase, Cherry-pick and History Rewriting
Answer
Situation read → Default rebase drops merge commits and linearises the commits.
What I'd do →
git rebase --rebase-merges origin/main(-r) recreates the merge topology.- Check the todo list: it shows
label,reset,mergecommands. - Resolve conflicts inside the rebuilt merges as they appear.
- Compare afterwards:
git range-diff origin/main@{1}...HEAD.
Why → --rebase-merges replaces the old --preserve-merges, which was removed because it handled interactive edits badly.
Interview tip → git range-diff shows what really changed between two versions of a rewritten branch.
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