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 

相关文章

Git安装和使用 Git安装和使用 刚开始用git的小白适用,,转自...
fatal: remote origin already exists.解决方法 第一个问题g...
git常用命令(二)查看历史记录 git log [--pretty=oneline]...
git之如何把本地文件上传到远程仓库的指定位置 git专栏收录该...
代码规范之 lint-staged 在代码提交之前,进行代码规则检查能...
方法:1、文件没有git操作时用“git checkout--文件”命令还...