Reputation: 32081
I have the following:
master
\
branchA -> branchB -> branchC
branchA
is in code review (rebased to master
)branchB
is current work (rebased to branchA
)branchC
adds a small feature unrelated to branchB
(rebased to branchB
currently)I want to change the order to branchA -> branchC -> branchB
, which is the order I'll submit merge requests to master.
When, on branchC
I do rebase branchA
it seems like I'm causing branchB
's commits to become part of branchC
.
I can rebase -i
to remove them. But I'm clearly doing something wrong here, and I don't really understand what it is I'm doing wrong. What is the correct way to reorder these branches?
Upvotes: 1
Views: 35
Reputation: 30212
The thing is that git can't just guess that branchB is something you don't want when you ask to rebase branchC on top of branchA. branchB is part of its history and so git guesses you want it too. There's a special syntax in rebase for this to work: git rebase --onto branchA branchB branchC
.
Addition: Copying in the relevant part of the documentation as it was quite helpful:
https://git-scm.com/book/en/v2/Git-Branching-Rebasing
$ git rebase --onto master server client
This basically says, “Take the client branch, figure out the patches since it diverged from the server branch, and replay these patches in the client branch as if it was based directly off the master branch instead.” It’s a bit complex, but the result is pretty cool.
Upvotes: 2