tags:

views:

57

answers:

1

Is there a way to move a sequential set of commits from one (local) branch to another? I have searched quite a bit and still haven't found a clear answer for what I want to do.

For example, say I have this:

master A---B---C
                \
feature-1        M---N---O---P---R---Q

And I have decided that the last 3 commits would be better off like this:

master  A---B---C
                 \
feature-1         M---N---O
                           \
f1-crazy-idea               P---R---Q

I know I can do this, and it does work:

$ git log --graph --pretty=oneline (copying down sha-1 ID's of P, R, Q)
$ git checkout feature-1
$ git reset --hard HEAD^^^
$ git checkout -b f1-crazy-idea
$ git cherry-pick <P sha1>
$ git cherry-pick <R sha1>
$ git cherry-pick <Q sha1>

I was hoping that instead there would be a more concise way to do this, possibly with git rebase, although I haven't had much luck.

Any insight would be greatly appreciated.

Thanks,

Jamie

+2  A: 

There is (git rebase --onto), but in this case you don't need to move them. Checkout feature-1, create a new branch f1-crazy-idea at the same spot (but stay on feature-1), and hard reset backwards 3

Michael Mrozek
@Michael: I didn't see your answer first, I delete mine.
VonC
+1 by the way ;)
VonC