我花了一段时间为这个问题创建了一个合适而简单的标题。
我正在开发分支代码,然后我意识到我已经完成的任务将被推到master。现在的问题是,我的分支也包含开发工作,因为我已经从开发中创建了分支。
我试着在互联网上搜索这个,但也许我找不到合适的搜索词。
请有人能帮助我在不合并开发代码的情况下直接合并我的工作来掌握吗,谢谢?
假设您的分支名为my-branch
。您可以使用这一行重写分支,就好像您最初从master
而不是development
:分支一样
git rebase development my-branch --onto master
换句话说,上面的命令说:
获取
my-branch
上development
无法访问的所有提交,并按顺序逐个重播到master
上。
只需切换到您的master
分支和cherry-pick
您想要在master中的提交。别忘了在摘樱桃之前先拔,更新你的主枝。
git commit // commit your work on the development branch
git log HEAD~n // to learn the commit id's.
// Replace n with number of commits you want to see
git checkout master
git pull
// cherry-pick in the order from earliest to the latest
git cherry-pick <commit-id-1>
....
git cherry-pick <commit-id-n>