解决 Git 中 fatal: refusing to merge unrelated histories

场景

两个分支: feature/lytest。我在test分支上做了一些修改,现在需要合并到feature/ly分支。

使用命令:

Administrator@DESKTOP-H841QIF MINGW64 /g/ly_doc/glive (feature/ly)
$ git merge --squash test
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

Administrator@DESKTOP-H841QIF MINGW64 /g/ly_doc/glive (feature/ly)
$ git merge --squash test --allow-unrelated-histories
CONFLICT (add/add): Merge conflict in ...
Auto-merging ...
Squash commit -- not updating HEAD
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
等等,就是这样完美的解决咯!

原文地址:https://www.cnblogs.com/hnxbp/p/14888989.html