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

hak*_*nin 32 git branch git-branch

我通常从开发创建新的分支

git checkout -b new-feature develop
Run Code Online (Sandbox Code Playgroud)

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

git checkout develop
git merge new-feature
Run Code Online (Sandbox Code Playgroud)

但这一次我创建了new-feature2brach new-feature,现在我无法合并develop.

有没有办法把new-feature2父母换成develop

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

ret*_*eto 41

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

git checkout new-feature2  
git rebase --onto develop new-feature new-feature2
# rebase the stuff from new-feature to new-feature2 onto develop branch
Run Code Online (Sandbox Code Playgroud)

或者使用樱桃选择'手动'

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
Run Code Online (Sandbox Code Playgroud)


mrm*_*mrm 12

你见过交互式变基吗?

git rebase -i develop
Run Code Online (Sandbox Code Playgroud)

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