Reputation: 11637
It is really difficult to understand Git rebase
for beginner. I always get weird result when I rebase
. I found that I can use --onto
to control where I should rebase to, but how can I control the from
side?
For example:
Let's say I am at branch 2 now, the number represent the time when the commit is done, and red color is my branch-2 commits which are not in master yet. If I want to get my branch 2 become below, what command should I use?
1) 1 -> 2 -> 8 -> 3 -> 5 -> 6 -> 7
2) 1 -> 2 -> 8 -> 5 -> 6 -> 7
In the beginning, I thought this can't be done, because my commit 3 will be gone, but I read it from Git website, this is actually valid.
3) 1 -> 2 -> 3 -> 5 -> 6 -> 8 -> 7
Can I do this? Basically to rebase only commit 7 on top of master?
The reason of asking these are because, auto rebase
always give me headache, so I rather to be able to specify, I want to rebase from
which commit onto
which commit. Am I able to do so? But I can't find the from
parameter.
Upvotes: 3
Views: 74
Reputation: 30297
First case:
git checkout branch2
git rebase máster
Second case:
git rebase --onto master branch2~3 branch2 #rebase branch2 but skipping revision 3
Third case:
git checkout branch2~
git cherry-pick master #pick revision 8
git cherry-pick branch2 # pick revision 7
# if you like the result
git branch -f branch2
git checkout branch2
Upvotes: 2