【Git】pull 分支报错 fatal: Need to specify how to reconcile divergent branches...

【Git】pull 分支报错 fatal: Need to specify how to reconcile divergent branches...

报错消息

  • 这是由于你拉取pull分支前,进行过merge合并更新分支操作,而其他人在你之前已经push过一个版本,导致版本不一致
➜  git:(test) git pull origin test
 * branch              test       -> 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:(test) git pull origin test
提示:您有不同的分支,需要指定如何协调它们。
提示:您可以通过在之前某个时间运行以下命令之一来做到这一点
提示:你的下一招:
提示:
提示: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:需要指定如何协调不同的分支。

解决方法

1、执行git config pull.rebase false,默认将pull下来的代码与现有改动的代码进行合并,该方法可能会造成代码冲突,需要处理下这个问题,代码冲突如果2个人都改了同一个文件,需要联系之前push的同学,看看这块代码怎么保存

2、回退到合并之前的代码,在进行pull拉取最新代码

  • 查看最近2次提交的历史版本
➜  git:(test) git log -2			# 查看最近2次提交的历史版本
commit 6018c237278f5265e78314049d6642e493ebdb0d
Author:Date:   Wed Jan 19 09:57:50 2022 +0800

   合并之后

commit 33df706e780d10af6435bda1fee85430604eebfd
Merge: 1d06cd1f 7589979d
Author:Date:   Tue Jan 18 16:11:21 2022 +0800

   合并之前

  • 根据历史版本记录,选择commit地址,回退到自己合并之前的版本
➜  git:(test) git reset --hard 33df706e780d10af6435bda1fee85430604eebfd
  • 再进行pull更新分支
➜  git:(test) git pull origin test
  • 最后再重新合并代码
➜  git:(test) git merge dev

更多git操作

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值