【问题标题】:Local branch behind remote branch (pull, rebase, fetch, merge)远程分支后面的本地分支(pull、rebase、fetch、merge)
【发布时间】:2016-02-12 06:03:56
【问题描述】:

如果我在我的分支 branch1 上工作,然后我推送一些提交,而我的团队成员也在 branch1 上工作——当我的团队成员需要推送他的更改时,他现在落后了。

他获取我最近的提交并尝试将他的更改与我的更改合并的最简单方法是什么?假设他在意识到这个错误之前已经提交了他的更改。

我以为你会这样做:

git pull origin/branch1 && git merge origin/branch1

但这似乎根本不起作用。

我相信你会做一个rebase,但我不确定这个过程;所有人都在谈论rebase 和master——但我现在不想用master 做任何事情。

【问题讨论】:

    标签: git github branch


    【解决方案1】:

    git pull origin/branch1 && git merge origin/branch1

    git pull

    git pull 实际上是这两个命令的别名:git fetch + git merge 所以你的命令的第二部分是无用的。


    获取更改的方法是这样的 - 几个选项:

    # Update your local repo with the latest code:
    git fetch --all --prune
    
    # Merge the changes (you already did a pull)
    git merge origin branch1
    

    或:

    # grab & merge the latest changes into your current branch 
    git pull origin branch1
    

    rebase

    如果您希望您的更改位于其他更改之上,那么您可以在拉取内容时使用--rebase 标志。

    # As before - update your local repo with the latest code:
    git fetch --all --prune
    
    # Merge the changes with the rebase flag
    git pull --rebase origin/branch1
    

    图片来源:http://blogs.atlassian.com/


    Stash + rebase 自动

    你有那些你可以设置的配置:

    rebase.autoStash + pull.rebase

    rebase.autoStash

    设置为 true 时,在操作开始前自动创建一个临时存储,并在操作结束后应用它。
    这意味着您可以在脏的worktree 上运行rebase。

    但是,请谨慎使用:rebase 成功后的最终存储应用程序可能会导致重大冲突。默认为 false。

    pull.rebase

    如果为 true,则在获取的分支之上重新设置分支,而不是在运行“git pull”时从默认远程合并默认分支。

    git config pull.rebase true
    git config rebase.autoStash true
    

    【讨论】:

      猜你喜欢
      • 2016-05-03
      • 2020-04-04
      • 2011-02-05
      • 2015-05-02
      • 1970-01-01
      • 2012-12-03
      • 2013-04-30
      • 2018-09-29
      • 2014-01-03
      相关资源
      最近更新 更多