Git fatal 拒绝合并无关的历史

今天在git合并分支的时候报了这个错误Git fatal:拒绝合并无关的历史

以前没有遇到过类似的问题。查了下是因为从Git 2.9版本开始这个命令有了些变化

1
2
3
4
5
6
7
8
9
10
11
* "git merge" used to allow merging two branches that have no common
base by default, which led to a brand new history of an existing
project created and then get pulled by an unsuspecting maintainer,
which allowed an unnecessary parallel history merged into the
existing project. The command has been taught not to allow this by
default, with an escape hatch "--allow-unrelated-histories" option
to be used in a rare event that merges histories of two projects
that started their lives independently.

* "git pull" has been taught to pass the "--allow-unrelated-histories"
option to underlying "git merge".

上面这段changelog大意是说:git merge之前允许合并两个没有公共提交记录的分支,这会导致不必要的提交记录历史被合并到当前分支。现在这个命令默认(从2.9版本开始)不允许这样做了。但是使用-allow unrelated history选项依然可以。

所以给git merge命令加上–allow-unrelated-histories参数就可以了

执行以下命令即可

1
git merge branchName --allow-unrelated-histories


参考

关注我的微信公众号[李一二],即时看更多的文章