Reputation: 8215
How can I do a git rebase that would so something equivalent to "take commit FROM commit c1 to branch tip of branch X, and transplant them onto other branch A2"
?
Visually, I need to do a rebase that would get me from this tree:
----------------...---*----------*----*---...---X
| \---...---A1 master c1 c2
\----...--A2
...to this one:
----------------...---*master
| \---...---A1
\----...--A2---*----*---...---X'
c1' c2'
I first thought the --fork-point
param was what I needed, but the result of trying to use it was "pure WTF" for me, guess it does something completely different, so I reverted to state before this failed attempt (what I did was: git checkout X; git rebase A2 --fork-point master
...maybe using c2's hash instead of master would've been the right thing, but the result of thing above was so incomprehensible to me that I totally abandoned this track...)
(P.S. I don't want to be told "why this is a bad idea". I know what I need, I have a clear picture of how commits should move around, and I also have a good understandings of all the changes that happened in between to what files, so I don't anticipate a conflict, and in case one happens I'm confident I can resolve it correctly.)
Upvotes: 1
Views: 145
Reputation: 30958
1.git cherry-pick
git checkout A2
git cherry-pick C1^..X
2.git rebase --onto
git rebase --onto A2 C1^ X
tip=`git log -1 --pretty=%h`
git checkout A2
git reset $tip --hard
Upvotes: -1
Reputation: 1119
Have you tried git rebase --onto
?
Specifically, if your goal is to cherry-pick the commits of source_branch
over target_branch
(i.e. commits Cy & Cz over commit C6)
C6 o => target_branch
|
C5 o o Cz => source_branch
| |
C4 o o Cy
| |
C3 o o Cx => some_intermediate_branch
| |
C2 o---
|
C1 o
Note that commit Cx
will not be picked - only commits Cy
& Cz
will be picked and applied above commit C6.
Upvotes: 2