I know the title is a little woolly - hence the quotes!
Say I have a branch, b_feature
that was branched from and merged into the main development branch b_master
. There exists another branch, b_release
, that I wish to add these changes to (as a point release). b_master
and b_release
have been diverged and will never be merged again.
---------Bm----k1-----Mm-----> b_master (k1 isn't to be included in b_release)
\ \ /
\ c1--c2--c3 (b_feature)
\
\----Br---------Mr-----> b_release
\ /
cA-cB-cC
I know I can cherry-pick the whole thing as a single diff with git cherry-pick -m Mm
, giving
----Br--Squashed----> b_release
where Squashed
is a commit containing all the changes of the feature, with the message of the merge Mm
.
But what if I want to retain the change history and the individual commit messages? I can always manually cherry-pick with this approximate workflow:
git checkout b_release
git checkout -b b_release_feature
git cherry-pick c1^..c3
git checkout b_release
git merge b_release_feature
git commit --amend --reedit-message=Mm
git branch -d b_release_feature
But this seems like a clunky workaround to a more elegant solution that I don't know!
rebase --onto b_release Bm Mm
also doesn't seem to produce the result I am looking for.
Any better way to do it?