'Git: created new branch from a wrong branch
I usually create new branch from develop
git checkout -b new-feature develop
then after the last commit I merge back to develop
git checkout develop
git merge new-feature
but this time I created new-feature2 brach from new-feature and now I cannot merge to develop.
Is there a way to switch new-feature2's parent to develop?
(The files I worked on were the same version as in develop so this should not require merging.)
Solution 1:[1]
Have you seen interactive rebase?
git rebase -i develop
is a pretty simple solution–it'll show all your commits from that branch. Just delete the "pick" lines from the unwanted branch.
Solution 2:[2]
what about creating a patch, checkout to the develop branch and apply the patch?
git checkout new-feature2
git format-patch new-feature
git checkout develop
git am name-of-the-patch.patch
Solution 3:[3]
You could also use git diff and git apply:
git diff new-feature..new-feature2 | git apply -
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mrm |
| Solution 2 | Jan Vorcak |
| Solution 3 | robinst |
