[英]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
. 但这一次我从
new-feature
创建了new-feature2
,现在我无法合并develop
。
Is there a way to switch new-feature2
's parent to develop
? 有没有办法切换
new-feature2
的父级develop
?
(The files I worked on were the same version as in develop
so this should not require merging.) (我处理的文件与
develop
的文件版本相同,因此不需要合并。)
You could rebase your feature over to the main base: 您可以将您的功能重新绑定到主基础:
git checkout new-feature2
git rebase --onto develop new-feature new-feature2
# rebase the stuff from new-feature to new-feature2 onto develop branch
or do it 'manually' by using cherry pick 或者使用樱桃选择'手动'
git checkout develop
git log --oneline new-feature..new-feature2
# for every commit call:
git cherry-pick <commit-id> # note, newer versions of cherry-pick allow multiple commits at once
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.
只需删除不需要的分支中的“选择”行。
what about creating a patch, checkout to the develop
branch and apply the patch? 如何创建补丁,结账到
develop
分支并应用补丁?
git checkout new-feature2
git format-patch new-feature
git checkout develop
git am name-of-the-patch.patch
你也可以使用git diff
和git apply
:
git diff new-feature..new-feature2 | git apply -
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.