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

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

For example, let's say I have this:

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

And I figured the last 3 commits would be better:

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

I know I can do this and it works:

$ git log --graph --pretty = oneline (copying down sha-1 ID 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 there would be a more concise way of doing this instead, perhaps with git rebase, although I had no luck.

Any insight would be greatly appreciated.

Thank,

Jamie

+2


source to share


1 answer


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

in the same location (but stay on feature-1

) and hard reset back 3



+6


source







All Articles