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

时间:2011-12-08 09:10:28

标签: git branch git-branch

我通常会从开发

创建新的分支
git checkout -b new-feature develop

然后在最后一次提交之后我合并回来开发

git checkout develop
git merge new-feature

但这次我从new-feature2创建了new-feature brach,现在我无法合并到develop

有没有办法将new-feature2的父级切换为develop

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

4 个答案:

答案 0 :(得分:40)

您可以将您的功能重新绑定到主基地:

git checkout new-feature2  
git rebase --onto develop new-feature new-feature2
# rebase the stuff from new-feature to new-feature2 onto develop branch

或使用樱桃选择'手动'来做

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

答案 1 :(得分:8)

您是否看过互动式变基?

git rebase -i develop

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

答案 2 :(得分:4)

如何创建补丁,结账到develop分支并应用补丁?

git checkout new-feature2

git format-patch new-feature

git checkout develop

git am name-of-the-patch.patch

答案 3 :(得分:1)

您还可以使用git diffgit apply

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