繁体   English   中英

如何“重组”一次提交?

[英]How to “rebase” a single commit?

考虑以下树:

A --- B --- C --- D --- E --- F --- master
 \
  \
    B' --- C' --- D' --- topic

其中(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

是不是可以用上面的命令执行单个命令?

首先重置你的分支,然后使用reflog找到提交樱桃选择:

git checkout -B topic master # re-create topic branch at the commit of master
git cherry-pick topic@{1} # copy the old tip of the topic branch

另一种 - 甚至可能更简单 - 方法是将rebase传递给一系列提交,这些提交只包含您想要重新设置的单个提交:

git rebase --onto master topic^ topic

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM