默认分类

解决Git中fatal: refusing to merge unrelated histories(解决远程与本地仓库版本不一致)

by nineone, 2023-05-26


Git的报错
在使用Git的过程中有时会出现一些问题,那么在解决了每个问题的时候,都需要去总结记录下来,下次不再犯。

一、fatal: refusing to merge unrelated histories

今天在使用Git创建项目的时候,在两个分支合并的时候,出现了下面的这个错误。

~/SpringSpace/newframe on  master ⌚ 11:35:56
$ git merge origin/druid
fatal: refusing to merge unrelated histories

这里的问题的关键在于:fatal: refusing to merge unrelated histories
你可能会在git pull或者git push中都有可能会遇到,这是因为两个分支没有取得关系。那么怎么解决呢?

二、解决方案

在你操作命令后面加 --allow-unrelated-histories
例如:

git merge master --allow-unrelated-histories
~/SpringSpace/newframe on  druid ⌚ 11:36:49
$ git merge master --allow-unrelated-histories
Auto-merging .gitignore
CONFLICT (add/add): Merge conflict in .gitignore
Automatic merge failed; fix conflicts and then commit the result.

如果你是git pull或者git push报 fatal: refusing to merge unrelated histories
同理:
git pull origin master --allow-unrelated-histories
等等,就是这样完美的解决咯!

none

作者: nineone

3 条评论
    sgpudcbmkf 回复
    sgpudcbmkf2025-10-05 00:25

    新盘新项目,不再等待,现在就是最佳上车机会!coinsrore.com

    trywnypfki 回复
    trywnypfki2025-10-07 06:10

    新盘 上车集合 留下 我要发发 立马进裙

    cnozlzrarc 回复
    cnozlzrarc2025-10-07 09:59

    2025年10月新盘 做第一批吃螃蟹的人coinsrore.com
    新车新盘 嘎嘎稳 嘎嘎靠谱coinsrore.com
    新车首发,新的一年,只带想赚米的人coinsrore.com
    新盘 上车集合 留下 我要发发 立马进裙coinsrore.com
    做了几十年的项目 我总结了最好的一个盘(纯干货)coinsrore.com
    新车上路,只带前10个人coinsrore.com
    新盘首开 新盘首开 征召客户!!!coinsrore.com
    新项目准备上线,寻找志同道合的合作伙伴coinsrore.com
    新车即将上线 真正的项目,期待你的参与coinsrore.com
    新盘新项目,不再等待,现在就是最佳上车机会!coinsrore.com
    新盘新盘 这个月刚上新盘 新车第一个吃螃蟹!coinsrore.com

2025 © typecho & elise 36 ms