I'm on branch foo, with parent A:
---A---foo
I want to partition the changes from A to foo into two branches, both based on A. I believe I can do half the job like this:
git checkout -b halfFoo
git reset HEAD~
# Only choose half the stuff.
git add -i
git commit
That gives me:
---A---foo
\
\-halfFoo
I know how to get it to this (git checkout -b otherHalfFoo; git commit -a):
---A---foo
\
\-halfFoo
\
\-otherHalfFoo
But what I'd like is to get this:
---A---foo
|\
| \-halfFoo
\
\-otherHalfFoo'
How can I do this without having to go through the 'git add -i' (and selecting the negative of what was chosen for halfFoo) again?
First, rewind to your previous commit, leaving in the changes since. Then branch off and apply some of the changes. Branch off from the original branch again, and apply the rest of the changes.
git branch original_tip_with_foo # if you want a reference to the foo commit
git reset HEAD~
git stash
git branch branch_2 # we'll get there in a moment ...
git checkout -b branch_1
git stash pop
git add -p
# ... add your first set of changes, for the first branch ...
git commit -m'first set of changes'
git stash
git checkout branch_2
git stash pop
git add -p
# ... add your second set of changes ...
git commit -m'second set of changes'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With