poloyy-archive
首页 / Git / Git - git 出现 fatal: refusing to merge unrelated histories 错误

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

Git  ·  原文归档  ·  点击图片可放大

背景

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

根本原因

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

解决方案一

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

解决方案二

使用强制命令

git pull origin master --allow-unrelated-histories

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

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

上一篇Git - git clone 远程仓库的指定分支 下一篇Git - git 查看远程仓库和本地的区别