by hardwaregeek · 5y ago · 0 comments
master: 1, 2, 3
feature-1: 1, 2, 3, 4, 5, 6,
feature-2: 1, 2, 3, 4, 5, 6, 7, 8
Then we merge feature-1 into master (numbers in parentheses indicate squashing): master: 1, 2, 3, (4, 5, 6)
feature-2: 1, 2, 3, 4, 5, 6, 7, 8
Then say we have another commit to master: master: 1, 2, 3, (4, 5, 6), 9
feature-2: 1, 2, 3, 4, 5, 6, 7, 8
And now we need to rebase feature-2 onto master. We can't do a normal rebase because git will try to do: feature-2: 1, 2, 3, (4, 5, 6), 9, 4, 5, 6, 7, 8
Instead we have to do a slightly tricky maneuver where we rebase just 7, 8 onto master, getting: feature-2: 1, 2, 3, (4, 5, 6), 9, 7, 8
It's not impossible and you can memorize the process pretty easily, but I'd love a natural solution to this problem.It keeps track of branchs and their parents by storing a tiny bit of metadata in the native git refs. It uses that information to perform recursive rebases: https://github.com/screenplaydev/graphite-cli/blob/main/src/...
It ends up working seamlessly - you just modify some branch, and then run `gt stack fix` to recursively rebase everything. (and then `gt stack submit` to sync everything to github :)
git checkout feature-2
git rebase feature-1 --onto master
rather confusing. is there a better way?edit: oh, you mentioned extra commits on master since the squash of feature-1. does that require two rebases?
git rebase feature-1 --onto master-at-feature-1
git rebase masterNo. Just git rebase --onto=master feature-1 will do the right thing.
(Personally I merge rather than rebasing to avoid this whole problem).
git rebase --onto master HEAD~2