I’m sure this is a simple thing that has been asked and answered, but I don’t know what terms to search for. I have this:
/--master--X--Y
A--B
\--C--D--E
Where I commited C, D, and E (locally only) on a branch, but then I realized that D and E are really independent of C. I want to move C to its own branch, and keep D and E for later. That is, I want this:
/--C
/--master--X--Y
A--B
\--D--E
How do I yank C out from under D and E?
You can use
git cherry-pickto grabC, and put it onY. AssumingYexists as the tip of a branch calledbranch-Y, you can run the following commands:So now
Cis on top ofY. ButDandEalso still containC(cherry-picking doesn’t move a commit, it just makes a copy of it). You’ll have to rebaseDandEon top ofB. AssumingEis the tip ofbranch-EandBisbranch-B, you can run the following commands:This will open up an interactive rebase session. Just remove commit
Centirely, and leaveDandEintact. You’ll then haveDandErebased on top ofBwithoutC.