Simple case
If the state of your repo
hack---F1----M1----F2 [feature] / / C1-----C2----C3 [master]
and you want to come to
hack---F1----M1----F2 [feature] / / C1-----C2----C3----F1'----F2' [HEAD=master]
you should use git cherry-pick , not git rebase -i (you don't need to manipulate interactive rebase here):
git checkout master git cherry-pick <commit-ID-of-F1> <commit-ID-of-F2>
General case
Correct me if I am wrong, but I understand what you mean by the general case as
cherry-pick, on top of master , all commits without merging between hack (exclusive) and the tip of feature (inclusive).
Further, I assume that this is really what you mean.
As you rightly noted in your comment, the approach described above does not scale very well, as the number of commits per sample manually increases:
hack---F1---F2--- .... --- F68--M1---F67---...---F99 [feature] / / C1-------------C2---------------C3 [master]
However, you can get git rev-list to automatically generate a list of revisions of interest using
git rev-list --reverse --no-merges --first-parent <commit-ID-of-hack>..feature
Edit: you also need the --first-parent flag to avoid collecting commits such as C1 and C2 , and the --reverse flag --reverse that commits are selected in the selected order.
You can pass the output of this command to git cherry-pick :
git checkout master git cherry-pick 'git rev-list --reverse --no-merges --first-parent <commit-ID-of-hack>..feature'
which will give
hack---F1---F2--- .... --- F68--M1---F67---...---F99 [feature] / / C1-------------C2---------------C3---F1'---F2'---...---F99' [HEAD=master]