iOS开发日常-Git版本管理之如何解决fatal: refusing to merge unrelated histories错误

前情概述

想将本地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

猜你喜欢

转载自blog.csdn.net/FTD_SL/article/details/86168274