git pull fatal: Need to specify how to reconcile divergent branches
git pull
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
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 的配置提醒。
简单来说,Git 发现你的本地分支(master)和服务器上的分支(origin/master)都各自有了新的提交(产生分叉了)。Git 不确定在你执行 git pull 时,是该通过 “合并(Merge)” 的方式,还是通过 “变基(Rebase)” 的方式来整理这些历史。
你现在该怎么办?
为了最简单、最稳妥地完成同步,建议执行以下命令:
方案一:使用“合并”方式(推荐,最直观)
这是最传统的做法,Git 会生成一个“Merge commit”来连接本地和远程的历史。执行:
git config pull.rebase false
git pull
方案二:使用“变基”方式(更整洁)
如果你希望你的本地提交历史看起来像是一条直线(没有多余的合并记录),可以使用 rebase。执行:
git config pull.rebase true
git pull
为什么会出现这个提示?
- 背景:Git 在较新的版本中,为了防止开发者不小心弄乱历史记录,强制要求开发者显式声明拉取代码时的行为。
git config pull.rebase false:意思是当你的本地有修改,远程也有修改时,执行git merge。这是最安全、最不容易搞乱代码的选择。
我的建议:
选择方案一 (git config pull.rebase false) 是最稳妥的,因为合并产生的“Merge commit”可以明确告诉你,什么时候是远程代码同步进来的,方便排查问题。
操作顺序:
- 输入
git config pull.rebase false(只需执行一次,后面不需要再输)。 - 输入
git pull。 - 如果提示需要输入提交信息(因为合并产生了 merge commit),直接保存退出(通常是按
Esc,输入:wq,然后回车)。
这样你的分支冲突就解决啦!
更多推荐



所有评论(0)