繁体   English   中英

如何将一个远程分支覆盖而不是合并到另一个分支?

[英]How can I overwrite, not merge, one remote branch into another branch?

我有两个分支。 分期和Beta。 暂存中包含代码(包括文件),我根本不需要。 如何让Beta完全覆盖Staging,以便这些文件或代码都不会从Staging合并到Beta。

我看到有些人建议这样做:

git checkout staging
git merge -s ours beta

但我不相信预先存在的文件会是“代码冲突”,因此不会被删除。 我错了吗? 如果我是对的,我将如何做到这一点?

您可以简单地删除staging并根据beta重新创建它:

git branch -D staging
git checkout beta
git branch staging

如果你不关心的悠久历史staging ,你可以重新创建它:

git checkout beta
git branch -f staging

如果您确实关心旧的staging历史,那么事情会变得更有趣:

git checkout staging        # First, merge beta into staging so we have
git merge -s theirs beta    # a merge commit to work with.

git checkout beta           # Then, flip back to beta's version of the files

git reset --soft staging    # Then we go back to the merge commit SHA, but keep 
                            # the actual files and index as they were in beta

git commit --amend          # Finally, update the merge commit to match the
                            # files and index as they were in beta.

我建议你重新命名,以防你改变主意。

git branch -m staging staging_oops
git checkout beta
git branch staging

如果你真的不能忍受额外的分支:

git branch -D staging_oops

如果分期历史不会成为问题,您可以简单地执行此操作。

git checkout staging 
git reset --hard beta

请记住,在上述命令和分段将有你的beta分支的工作之后,分段的历史将会消失。

暂无
暂无

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

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