Say I have 2 parallel long lived branches: master
and experimental
. And I do some work in a topic branch off of experimental
, and I do this for a couple features (feature1
, feature2
, feature3
). How would I transplant the work done in feature2
onto master
?
My initial repository:
master
|
A-B-C
\
D-E I L P
\ / \ / \ /|
F-G-H \ / \ / |
| J-K \ / experimental
feature1 | M-N-O
feature2 |
feature3
My desired repository:
master
|
A-B-C-----------------------------J'-K'
\
D-E I L P
\ / \ / \ /|
F-G-H \ / \ / |
| J-K \ / experimental
feature1 | M-N-O
feature2 |
feature3
One way I can think of doing it is git checkout master; git cherry-pick J K
but that's error prone and the topic branch might have many different commits.
I would expect it to work something like git checkout master; git <transplant-commits-in-topic-branch-onto-current-branch> feature2
, but all of the rebasing commands I'm familiar with transplant all the diffs from the common ancestor (in this case A
), I want to transplant just the diffs between I
and K
, and not mess with commit hashes.
A bit of context: I'm working on a codebase which was forked off of an original, however I'd like to contribute certain features back. And I develop all the new features in topic branches which I then merge back into my master.
If you're just trying to move
feature2
ontomaster
, and 'I' and 'K' don't depend on changes made infeature1
, you can transplant it with:That syntax reads, loosely, as "Rebase
feature2
ontomaster
. It's original upstream wasfeature1
."Then if you merge
feature2
intomaster
, it'll be a fast-forward merge.If, however,
feature2
depends on changes infeature1
that won't be onmaster
, the whole situation gets much more complicated, and what you want to do depends entirely on your workflow and how you relate to the parent project. Cherry-picking would work... so long as you're willing to make later merges of your feature branches complicated against the origin's master. Or you could rebase all of your branches so thatfeature2
applies cleanly againstmaster
, or... about a dozen other methods. It really depends on your long term plan for these branches. In general, cutfeature2
(andfeature3
and so on) offmaster
if you can help it. It'll save you a lot of trouble down the line.