Git - git 出现 fatal: refusing to merge unrelated histories 错误

背景

git pull失败,提示: fatal: refusing to merge unrelated histories 

 

根本原因

因为两个根本不相干的 git 库, 一个是本地库, 一个是远端库, 然后本地要去推送到远端, 远端觉得这个本地库跟自己不相干, 所以告知无法合并

 

解决方案一

git clone远程仓库到本地,将需要推送的内容放到该仓库下 , 然后提交上去 , 这样算是一次update操作

 

解决方案二

使用强制命令

git pull origin master --allow-unrelated-historie 

后面加上 --allow-unrelated-histories  , 把两段不相干的分支进行强行合;这里可能会进入一个编辑页面,只需要先ESC,然后敲:q! 即可

后面再push就可以了 git push -u origin master 

posted @ 2020-01-21 16:21  小菠萝测试笔记  阅读(2518)  评论(0编辑  收藏  举报