Git报错--解决fatal: refusing to merge unrelated histories
Git的报错
在使用Git的过程中有时会出现一些问题,那么在解决了每个问题的时候,都需要去总结记录下来,下次不再犯。
一、错误提示
fatal: refusing to merge unrelated histories
git merge origin/druid
fatal: refusing to merge unrelated histories
二、错误出现场景
- 分支合并时
2.git pull或者git push
三、解决方案
3.1 针对分支合并场景
在你操作命令后面加--allow-unrelated-histories
把两段不相干的分支进行强行合并
例如:
git merge dev--allow-unrelated-histories
git merge dev--allow-unrelated-histories
Auto-merging .gitignore
CONFLICT (add/add): Merge conflict in .gitignore
Automatic merge failed; fix conflicts and then commit the result.
3.2 针对pull、push场景
根本原因
因为两个根本不相干的git库,一个是本地库 一个是远端库,然后本地要去推送到远端,
远端觉得这个本地库跟自己不相干,所以告知无法合并
解决方式1
git clone远程仓库到本地,将需要推送的内容放到该仓库下,然后提交上去,这样算是一次update操作
解决方式2
使用强制命令
git pull origin master --allow-unrelated-historie
后面加上 --allow-unrelated-histories,把两段不相干的分支进行强行合并;
这里可能会进入一个编辑页面,只需要先ESC,然后敲:q! 即可
后面再push就可以了 git push -u origin master

浙公网安备 33010602011771号