Reputation: 1425
I have the following scenario
Branch A: c1, c2
Branch B: c1, c2, c3, c4
Branch D: c1, c2, c3, c4, c5, c6
Now, branch D was meant to branch from Branch A, but I mistakenly branched from branch B. The commits, c5 and c6 are not related to commits, C3 and c4.
How do I go about making a new Branch, E, from Branch A, and moving just commits C5 and C6 over to this new branch such that it is structured like this:
Branch E: c1, c2, c5, c6
Upvotes: 0
Views: 1196
Reputation: 566
If you really only have 2 commits to move you can do:
git checkout -b E A
git cherry-pick c5
git cherry-pick c6
But git rebase
let's you do multiple commits at a time:
gut checkout -b E D
git rebase --onto A B
First, we start a new branch E at D. Then the rebase syntax is to take everything in E "since B" and recommit it "onto" A.
-i
flag for interactive and you should only see commits c5 and c6 in the "todo".Upvotes: 2