Move a sequential set of commits from one (local) branch to another

Posted by jpswain09 on Stack Overflow See other posts from Stack Overflow or by jpswain09
Published on 2010-04-12T03:46:15Z Indexed on 2010/04/12 3:53 UTC
Read the original article Hit count: 287

Filed under:

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

© Stack Overflow or respective owner

Related posts about git