Change parent Git branch
Let's say we have a branching structure like:
develop -> --- a --- b --- c
\ \
feature 1 -> \ --- d --- e
\
feature 2 -> --- f --- g
After doing work on function 1, I decided that it really should be forked as a sub-task of function 2.
Is there a way for feature 1 to "undo" forking from development and disabling feature 2 instead, while keeping its commits?
Example:
develop -> --- a --- b --- c
\
feature 1 -> \ --- d --- e
\ /
feature 2 -> f --- g
source to share
You usually look at git rebase
for this kind of thing, but it won't work because a rebase from feature1 to feature2 will include commits b and c, which you don't want.
Willem's suggestion to use cherry-pick
is probably the way to go.
Create a new branch:
git checkout -b feature1b feature1
Cherry picks the objects of interest (here I say "last two commits of function1", but you can specify the range of commits using real commit IDs, etc.):
git cherry-pick feature1~2..feature1
At this point, the branch feature1b
matches your desired history. You can do some additional cleanup depending on your needs:
Delete the old branch:
git branch -D feature1
Rename the new branch:
git branch -m feature1
source to share