git pull "fatal: 拒绝合并无关的历史"

在git仓库中新建了一个仓库,想要把本地的项目传上去

在项目中:

git init
git add .
git commit "提交说明"

连接远程主机:

git remote add  origin  远程仓库地址

push到远程仓库:

git  push origin master
MacBook-Pro:~/go/src/demo/open$ git push -u origin master
To codehub.devcloud.huaweicloud.com:t00001/open.git
 ! [rejected]        master -> master (non-fast-forward)
error: 推送一些引用到 'git@codehub.devcloud:Openxt00001/open.git' 失败
提示:更新被拒绝,因为您当前分支的最新提交落后于其对应的远程分支。
提示:再次推送前,先与远程变更合并(如 'git pull ...')。详见
提示:'git push --help' 中的 'Note about fast-forwards' 小节。

提示先拉取更新

MacBook-Pro:~/go/src/demo/open$ git pull origin master
来自 codehub.devcloud.enxt00001/open
 * branch            master     -> FETCH_HEAD
fatal: 拒绝合并无关的历史

解决方法:
在拉取时使用以下命令:

git pull origin master --allow-unrelated-histories 

对此,官方解释如下:

By default, git merge command refuses to merge histories that do not share a common ancestor. This option can be used to override this safety when merging histories of two projects that started their lives independently. As that is a very rare occasion, no configuration variable to enable this by default exists and will not be added.

默认情况下,git合并命令拒绝合并没有共同祖先的历史。当两个项目的历史独立地开始时,这个选项可以被用来覆盖这个安全。由于这是一个非常少见的情况,因此没有默认存在的配置变量,也不会添加。(有道翻译)

之后在执行:

git push origin master
  • 6
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xidianzxm

您的打赏是我继续创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值