Git:从错误的分支创建了新的分支

时间:2021-04-11 23:43:11

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 brach,现在我无法合并开发。

Is there a way to switch new-feature2's parent to develop?

有没有办法切换new-feature2的父级进行开发?

(The files I worked on were the same version as in develop so this should not require merging.)

(我处理的文件与开发中的文件版本相同,因此不需要合并。)

4 个解决方案

#1


32  

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

#2


6  

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.

是一个非常简单的解决方案 - 它将显示来自该分支的所有提交。只需删除不需要的分支中的“选择”行。

#3


4  

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

#4


1  

You could also use git diff and git apply:

你也可以使用git diff和git apply:

git diff new-feature..new-feature2 | git apply -

#1


32  

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

#2


6  

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.

是一个非常简单的解决方案 - 它将显示来自该分支的所有提交。只需删除不需要的分支中的“选择”行。

#3


4  

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

#4


1  

You could also use git diff and git apply:

你也可以使用git diff和git apply:

git diff new-feature..new-feature2 | git apply -