fatal: refusing to merge unrelated histories

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

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

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

具体的方法,

第一种方法:

从远端库clone拉下来代码 , 本地要加入的代码放到远端库下载到本地的库, 然后提交上去 , 因为这样的话, 你基于的库就是远端的库, 这是一次update

第二种方法:
使用这个强制的方法

git pull origin master --allow-unrelated-histories

后面加上 --allow-unrelated-histories , 把两段不相干的 分支进行强行合并

后面再push就可以了 git push gitlab master:init

gitlab是别名 , 使用

Java代码
git remote add gitlab ssh://xzh@192.168.1.91:50022/opt/gitrepo/withholdings/WithholdingTransaction

master是本地的branch名字
init是远端要推送的branch名字

本地必须要先add ,commit完了 才能推上去

关于这个问题,可以参考http://stackoverflow.com/questions/37937984/git-refusing-to-merge-unrelated-histories。

在进行git pull 时,添加一个可选项

git pull origin master --allow-unrelated-histories

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值