美文网首页
记Git报错-refusing to merge unrelat

记Git报错-refusing to merge unrelat

作者: soul找到你 | 来源:发表于2019-03-11 18:04 被阅读0次

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

    其实这个问题是因为 两个 根本不相干的 git 库, 一个是本地库, 一个是远端库, 然后本地要去推送到远端, 远端觉得这个本地库跟自己不相干, 所以告知无法合并,于本地仓库和远程仓库实际上是独立的两个仓库。假如我之前是直接clone的方式在本地建立起远程github仓库的克隆本地仓库就不会有这问题了。

    发现可以在pull命令后紧接着使用--allow-unrelated-history选项来解决问题(该选项可以合并两个独立启动仓库的历史)。

    命令:$ git pull origin master –allow-unrelated-histories

    以上是将远程仓库的文件拉取到本地仓库了。 

    紧接着将本地仓库的提交推送到远程github仓库上,使用的命令是:

    $ git push <远程主机名> <本地分支名>:<远程分支名>也就是$gitpush originmaster:master提交成功。

    连接远程仓库,在本地的命令框中输入下面的命令      git remote add origin https://github.com/OliveKong/poster.git 

    相关文章

      网友评论

          本文标题:记Git报错-refusing to merge unrelat

          本文链接:https://www.haomeiwen.com/subject/yxabpqtx.html