33

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

我看到有人建议这样做:

git checkout staging
git merge -s ours beta

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

4

4 回答 4

30

You can simple delete staging and re-create it based on beta:

git branch -D staging
git checkout beta
git branch staging
于 2013-04-23T14:24:33.640 回答
25

如果您不关心的旧历史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.
于 2013-04-23T14:27:18.477 回答
9

我建议你只是重命名它,以防你改变主意。

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

如果你真的无法忍受周围有那个额外的分支:

git branch -D staging_oops
于 2013-04-23T14:26:48.213 回答
0

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

git checkout staging 
git reset --hard beta

请记住,在上述命令之后,staging 的历史将消失, staging将拥有您的beta分支的工作。

于 2017-05-17T06:16:00.450 回答