考虑下面的树:
A --- B --- C --- D --- E --- F --- master
\
\
B' --- C' --- D' --- topic
Run Code Online (Sandbox Code Playgroud)
在哪里(B != B')。我想做git rebase --onto master master topic,但这会产生冲突。但情况更简单:我想将单个topic提交放到 master 上。
git checkout master
git cherry-pick topic
git checkout topic
git reset --hard master
git checkout master
git reset --hard HEAD~1
Run Code Online (Sandbox Code Playgroud)
难道不能用一个命令来完成上面的命令吗?
首先重置您的分支,然后使用 reflog 查找对cherry pick 的提交:
\n\ngit checkout -B topic master # re-create topic branch at the commit of master\ngit cherry-pick topic@{1} # copy the old tip of the topic branch\nRun Code Online (Sandbox Code Playgroud)\n\n另一种 \xe2\x80\x93 可能更简单的 \xe2\x80\x93 方法是传递 rebase 一系列提交,其中仅包含您想要重新设置的单个提交:
\n\ngit rebase --onto master topic^ topic\nRun Code Online (Sandbox Code Playgroud)\n