Here are several ways to reach similar goals :
# start with a temp branch at commit DEF :
git checkout -b temp DEF
git rebase targetbranch
# or, if the fork point between 'foobar' and 'targetbranch' is not
# at GHI, instruct rebase to only take commits starting from GHI :
git rebase --onto targetbranch GHI^
git checkout targetbranch
git merge --no-ff temp
git branch -d temp
# create a temp branch from your current tip :
git checkout -b temp
# list all commits to pick:
git cherry-pick GHI DEF
# merge temp branch into targetbranch:
git checkout targetbranch
git merge --no-ff temp
git branch -d temp
- using
cherry-pick
(take 2):
# create a temp branch from your current tip :
git checkout -b temp
# the range of commits to pick should be :
# the range "first parent of M" .. "second parent of M"
git cherry-pick M^..M^2
# merge temp branch into targetbranch:
git checkout targetbranch
git merge --no-ff temp
git branch -d temp