前情概述
想将本地git管理的项目推送到github这样的远程仓库中,本地分支提交了部分内容,远程分支也有提交历史。
问题
本地添加远程仓库后(git remote add origin xx),执行git pull想拉取远程分支的内容时,报错:
daqiangshendeMacBook-Pro:DQS~SourceCode dqs$ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 1 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
nothing to commit, working tree clean
daqiangshendeMacBook-Pro:DQS~SourceCode dqs$ git pull
fatal: refusing to merge unrelated histories
原因分析
本地分支和远程分支分别提交后,当我们在git push之前执行git pull时,git认为这两次提交的历史是不相关的,无法合并。
解决
强制合并
git pull origin master --allow-unrelated-histories
本文阐述了在本地Git项目与远程GitHub仓库存在独立提交历史时,如何解决合并冲突的问题。详细介绍了错误提示refusing to merge unrelated histories的原因及解决方法,包括使用强制合并选项。
1万+

被折叠的 条评论
为什么被折叠?



