[GIT] 解决:Git Fatal: refusing to merge unrelated histories

1 问题背景

  • 在本地git commit 后,准备在 git push 之前做一次git pull,结果报:
$ git pull
fatal: refusing to merge unrelated histories

2 问题分析

  • 根本原因:你可能会在git pull或者git push中都有可能会遇到,这是因为两个分支没有取得关系。

3 解决方法

那么怎么解决呢?

  • 在你操作命令后面加--allow-unrelated-histories

例如:git merge master --allow-unrelated-histories

$ 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 pushfatal: refusing to merge unrelated histories

同理:git pull origin master --allow-unrelated-histories

  • 【特别注意】如上操作后,如果提示出现代码冲突,则需自行手动解决之。

X 参考文献

posted @ 2024-03-05 22:18  千千寰宇  阅读(33)  评论(0编辑  收藏  举报