【问题标题】:Replace one local branch with another local branch... and preserving tracking用另一个本地分支替换一个本地分支......并保留跟踪
【发布时间】:2015-10-11 07:48:47
【问题描述】:

我有 2 个本地分支正在跟踪不同的存储库:

  • local-live(跟踪我们的实时存储库)
  • 本地暂存(跟踪暂存存储库)

我们设置了“持续部署”,因此当我将本地暂存升级时,暂存环境将根据更改进行更新。我希望 staging 以反映实时的代码(目前情况并非如此)。

如何用我的“local-live”分支中的代码替换我的“local-staging”分支?我想擦除所有登台更改,使登台反映现场直播的内容。我希望我的本地暂存仍然跟踪暂存存储库(即,暂存中的“git push”将按预期运行)

希望这很清楚。谢谢。

【问题讨论】:

    标签: git git-branch branching-and-merging git-remote


    【解决方案1】:

    您想进行硬重置。

    git checkout local-staging
    git reset --hard local-live
    

    【讨论】:

    • 我虽然“git reset”中的最后一个参数应该是你想要重置的提交。它也适用于分支名称吗?
    • @RayL 是的,绝对。试试看。如果可行,请接受答案..:)
    • 最简洁的答案。谢谢!
    【解决方案2】:

    您似乎想将您的实时分支合并到您的暂存分支中。

    这里有一个详细的指南:

    http://www.git-tower.com/learn/git/ebook/command-line/branching-merging/merging

    基本上你必须这样做:

    $ git checkout local-staging
    $ git merge local-live
    


    现在,如果您想将实时分支的更改放在暂存分支之上,您应该使用 rebase。 并执行以下操作:
    $ git checkout local-live
    $ git rebase local-staging
    $ git checkout local-staging
    $ git merge local-live
    

    检查一下:

    https://git-scm.com/book/en/v2/Git-Branching-Rebasing


    现在,如果您不想合并分支,则应该进行破坏性操作:O

    您可以进行“硬重置”和“强制推送”。

    $ git checkout local-staging
    $ git reset --hard <desired commit of local-live>
    $ git push --force origin local-staging
    

    更多信息:

    https://es.atlassian.com/git/tutorials/undoing-changes/git-reset

    【讨论】:

    • 我根本不想合并。我想替换暂存的内容(松开暂存的任何更改)。抱歉,我刚刚更新了问题。希望这是有道理的。
    猜你喜欢
    • 1970-01-01
    • 2016-11-07
    • 1970-01-01
    • 2012-03-05
    • 2013-04-30
    • 2011-07-27
    • 2010-09-15
    • 2011-08-02
    相关资源
    最近更新 更多