如何“rebase”单个提交?

use*_*454 5 git

考虑下面的树:

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)

难道不能用一个命令来完成上面的命令吗?

kni*_*ttl 4

首先重置您的分支,然后使用 reflog 查找对cherry pick 的提交:

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

另一种 \xe2\x80\x93 可能更简单的 \xe2\x80\x93 方法是传递 rebase 一系列提交,其中仅包含您想要重新设置的单个提交:

\n\n
git rebase --onto master topic^ topic\n
Run Code Online (Sandbox Code Playgroud)\n