gpt4 book ai didi

Git:将特定提交移动到另一个分支

转载 作者:IT王子 更新时间:2023-10-29 01:26:52 25 4
gpt4 key购买 nike

A 有两个分支的仓库。

主分支提交:

c1, c2, c3, c4, c5, c6, c7, ..., c15, ...

暂存分支提交:

c1、c2、c3、c4、c5、c6、c7

我想将 c7 之后的 Master 分支的所有提交移动到 staging 分支

然后还原主分支

git reset --hard c7-hash

如何将特定提交从一个分支移动/复制到另一个分支?

最佳答案

在您描述的情况下,staging 分支上的所有提交也都在 master 分支上,这非常简单:

git checkout staging
git merge master
git checkout master
git reset --hard c7-hash

merge 将是一个快进。

在一般情况下,您可以使用 git cherry-pick c8 c9 c10 c11 c12 c13 c14 c15挑选对当前分支的个人提交。一种较短的方式来挑选所有在 master 而不是当前分支上的提交是 git cherry-pick ..master ,还有其他示例由 git help cherry-pick 显示

关于Git:将特定提交移动到另一个分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14697801/

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