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

/ 分享 / 无站内评论 / 661浏览

前言

在github或者码云上新建项目时,idea commit到本地仓库后,打算push会提示如下错误

22:02	Push rejected: Push to origin/master was rejected

pull会提示错误:

22:03	Git Pull Failed: refusing to merge unrelated histories

解决方案

使用git到项目目录下执行如下: 1.

git pull origin master --allow-unrelated-histories

$ git pull origin master --allow-unrelated-histories
From https://gitee.com/SAnSAni/fruitshop
 * branch            master     -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 README.md | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 README.md

2.弹出的内容不用管,vim命令:wq退出即可。

3.回到idea,使用git:pull master 分支,这时候会把readme文件pull下来,这时候差不多成功了。

4.再次push即可。

22:02	Push rejected: Push to origin/master was rejected

22:03	Git Pull Failed: refusing to merge unrelated histories

22:06	Push successful: Pushed 2 commits to origin/master
召唤蕾姆
琼ICP备18000156号

鄂公网安备 42011502000211号