【Git】Git pull代码时,出现报错:hint: you have divergent branches and need to specify how to reconcile them.
创始人
2024-11-14 21:06:39

问题描述

在执行 git pull 时,出现了如下提示:

➜  git:(test) git pull origin develop  * branch              develop       -> FETCH_HEAD hint: You have divergent branches and need to specify how to reconcile them. hint: You can do so by running one of the following commands sometime before hint: your next pull: hint:  hint:   git config pull.rebase false  # merge (the default strategy) hint:   git config pull.rebase true   # rebase hint:   git config pull.ff only       # fast-forward only hint:  hint: You can replace "git config" with "git config --global" to set a default hint: preference for all repositories. You can also pass --rebase, --no-rebase, hint: or --ff-only on the command line to override the configured default per hint: invocation. fatal: Need to specify how to reconcile divergent branches. 

原因分析:

先翻译下提示的信息:
git:(develop) git pull origin develop
提示:您有不同的分支,需要指定如何协调它们。
提示:您可以通过在之前某个时间运行以下命令之一来做到这一点
提示:你的下一次获取:
提示:
提示:git config pull.rebase false # 合并(默认策略)
提示:git config pull.rebase true # Rebase
提示:git config pull.ff only # 仅快进
提示:
提示:可以将“git config”替换为“git config——global”来设置默认值
提示:首选所有存储库。你也可以传递——rebase,——no-rebase,
提示:或命令行上的——ff-only,以覆盖配置的默认per
提示:调用。
fatal:需要指定如何协调不同的分支。

原因:因为你在pull代码之前,进行了merge并更新代码的操作,而其他人在你之前提交了一个版本,导致版本不一致。


解决方案:

  • 方案一:
    • 按照提示,直接执行git config pull.rebase false
    • 该操作是默认获取最新代码,并与本地合并,如果有冲突,需要解决冲突。
  • 方案二:
    • 该方法适用于两个分支的合并
    • 先保存下修改内容,然后将当前分支回退到修改代码之前的版本,执行pull以获取最新代码
    • 然后将要合并的分支合并到当前分支,再将自己的改动添加上,
    • 最后再提交代码

相关内容

热门资讯

裸辞做“一人公司”,我后悔了 去年这个时候,一位以色列程序员正在东南亚旅行。他顺手把一个在脑子里转了很久的想法做成了产品,一个让任...
南京建成国内首个Pre-6G试... 4月21日,2026全球6G技术与产业生态大会在南京开幕。全息互动技术展台前,一名远在北京的工作人员...
超梵求职受邀参加“2025抖音... 超梵求职受邀参加“2025抖音巨量引擎成人教育行业生态大会”,探讨分享优质内容传播,服务万千学员。 ...
摩托罗拉Razr 2026(R... IT之家 4 月 22 日消息,摩托罗拉宣布新一代 Razr 折叠手机将于 4 月 29 日在美国发...
库克卸任,特纳斯领航:苹果新纪... 苹果首席执行官蒂姆·库克将卸任,硬件工程主管约翰·特纳斯将接任,苹果公司今天宣布此事。 库克将在夏季...