如何使用主机上的更改更新主题分支? [英] How to update topic branch with upstream changes on master?

查看:111
本文介绍了如何使用主机上的更改更新主题分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始在主题分支上进行一些工作

 • - • - •<主题
/
• - •< master

我推送主题分支

  $ git push origin topic 

其他人将更改推送给master

 • - • - •<来源/主题
/
• - • - • - •<原产地/主人



如何更新我的本地主人并重定我的主题?



历史应该看起来像这样

 • - • - •<主题
/
• - • - • - •<大师



我在做什么



 ;更新大师
$ git checkout master
$ git fetch origin
$ git merge --ff-only origin / master

; rebase topic
$ git checkout topic
$ git rebase master



问题



我对 topic 的所有提交都被视为未提交。所以当我尝试 git push origin topic 时,我得到

 ! [rejected] topic  - >主题(非快进)
错误:无法将某些引用推送到'/path/to/repo.git'
提示:更新被拒绝,因为当前分支的提示位于$ b后面$ b提示:它的远程副本。合并远程更改(例如'git pull')
提示:再次按下之前。
提示:有关详细信息,请参阅'git push --help'中的'关于快速转发的注意事项'。



解决方案?



请注意,我不是想要将主题分支与 master 合并。我只想简化本地仓库,而不必不必要地合并分支。

解决方案

  CDE<话题,来源/主题
/
A-B< master,origin / master

然后有人确实有效。

  CDE<话题,来源/主题
/
A-B-F-G <原产地/主人
^
主人

您取得F& G来源,然后将主题重新命名为主。所以现在你的仓库看起来就像这样。

  C-D-E <出处/主题
/
A-B-F-G < master,origin / master
\
C'-D'-E'<主题

这就是问题所在。 E的原点/主题不能被快速转发到E的主题。 Rebase实际上只针对尚未推送到源的提交。由于您已将C,D和E推送到起源/主题,因此您必须在远程存储库上重写历史记录。因此错误。所以你真的有三个选择:停止推送一个热门分支。
$ b 如果只有你正在研究主题,那么就没有必要推动它。只要在主人之上继续重新定义主题,并且完成后,快速将主人合并到主题&推大师。删除本地主题分支。 Voila!


  • 合并主题&主。如果您需要在专题分支上进行协作,您应该将其吸收并合并。 强制远程转发:

    git push origin topic -f

    这会强制原点/主题为E'。除了通过在远程仓库中重写历史记录,你会有火和硫磺,人类的牺牲,狗和猫共同生活,群众歇斯底里...和你的开发人员不喜欢你。根本不推荐。



  • I start some work on a topic branch

        •-•-• < topic
       /
    •-•       < master
    

    I push the topic branch

    $ git push origin topic
    

    Someone else pushes changes to master

        •-•-• < origin/topic
       /
    •-•-•—•   < origin/master
    

    How do I update my local master and rebase my topic?

    History should look like this

            •-•-• < topic
           /
    •-•-•—•       < master
    

    What I am trying

    ; update master
    $ git checkout master
    $ git fetch origin
    $ git merge --ff-only origin/master
    
    ; rebase topic
    $ git checkout topic
    $ git rebase master
    

    The problem

    All of my commits on topic are seen as uncommitted. So when I try git push origin topic, I get

     ! [rejected]        topic -> topic (non-fast-forward)
    error: failed to push some refs to '/path/to/repo.git'
    hint: Updates were rejected because the tip of your current branch is behind
    hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
    hint: before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    

    The solution?

    Please note, I do not want to merge my topic branch with master. I'd simply like to get my local repo updated without having to merge branches unnecessarily.

    解决方案

    Let me rework your example for clarity.

        C-D-E < topic, origin/topic
       /
    A-B < master, origin/master
    

    Then someone does work.

        C-D-E < topic, origin/topic
       /
    A-B-F-G < origin/master
      ^
    master
    

    You fetched F & G from origin, and then rebased topic onto master. So now your repository looks like this.

        C-D-E < origin/topic
       /
    A-B-F-G < master, origin/master
           \
            C'-D'-E' < topic
    

    And this is the problem. origin/topic at E can not be fast-forwarded to topic at E'. Rebase is really only meant for commits that have not been pushed to origin. Since you pushed C, D, and E to origin/topic already, you would have to rewrite history on the remote repository. Hence the error. So you really have three options:

    1. Stop pushing a topical branch. If it's only you who is working on topic, there's no need to push it. Just keep rebasing topic on top of master, and when done, fast-forward merge master to topic & push master. Delete local topic branch. Voila!

    2. Merge topic & master. If you need to collaborate on a topical branch, you should probably suck it up and merge.

    3. Force the remote rebase:

      git push origin topic -f

      This will force origin/topic to E'. Except by re-writing history in the remote repository, you'll have fire and brimstone, human sacrifice, dogs and cats living together, mass hysteria... and your fellow developers not liking you very much. Not recommended at all.

    这篇关于如何使用主机上的更改更新主题分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆