Stacked Diffs with git rebase —onto
10 days ago
- #git
- #stacked-diffs
- #version-control
- Stacked diffs (or stacked PRs) break large features into smaller, dependent PRs for easier reviews.
- Regular `git rebase` can cause issues with stacked branches by duplicating commits or creating conflicts.
- `git rebase --onto <new-base> <old-base> <branch>` allows clean rebasing of dependent branches without unwanted commits.
- Marker branches (`feature-2-base`) help track the previous state of the parent branch for accurate rebasing.
- Steps for first sync: rebase parent branch (`feature-1`), rebase dependent branch (`feature-2`) using `--onto`, update marker branch.
- Repeat sync process when `main` updates: rebase parent, rebase dependent branch, update marker.
- Clean up merged feature commits from dependent branches using interactive rebase (`git rebase -i main`).
- Force pushes (`git push --force-with-lease`) are necessary due to commit hash changes from rebasing.
- Discipline with marker branches is crucial to avoid sync issues.
- Keep stacked diffs manageable (2-3 levels max) to balance benefits and maintenance overhead.