gpt4 book ai didi

git - 如何 "rebase"一次提交?

转载 作者:太空狗 更新时间:2023-10-29 13:43:11 25 4
gpt4 key购买 nike

考虑下面的树:

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 找到提交到 cherry pick:

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 范围内的提交,这些提交只包含你想要 rebase 的单个提交:

git rebase --onto master topic^ topic

关于git - 如何 "rebase"一次提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29588884/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com