当前位置:   article > 正文

Git merge 出现 refusing to merge unrelated histories_error merging: refusing to merge unrelated histori

error merging: refusing to merge unrelated histories

GIT合并不相关的分支

问题

不管由于什么操作,导致了仓库中有两个不相关的分支,如下图,分支topic和分支master,并没有相交的部分,现在需要将topic分支合并到master分支上。

	A---B---C topic
	          
    D         master
  • 1
  • 2
  • 3

切换到master分支 作为当前分支执行merge命令

git merge topic
  • 1

出现报错信息

Could Not Merge topic: refusing to merge unrelated histories 
  • 1

解决方案

查阅GIT官网,发现merge有一个选项--allow-unrelated-histories,对于这个选项的解释是默认情况下, git merge 命令拒绝合并不具有共同祖先的历史。 在合并两个独立开始的项目的历史记录时,可以使用此选项来覆盖此安全性。 由于这是一种非常罕见的情况,因此默认情况下不存在启用此功能的配置变量,也不会添加。 这个选项也只在合并的时候生效。

–allow-unrelated-histories
By default, git merge command refuses to merge histories that do not share a common ancestor. This option can be used to override this safety when merging histories of two projects that started their lives independently. As that is a very rare occasion, no configuration variable to enable this by default exists and will not be added.
Only useful when merging.

重新执行命令

git merge topic --allow-unrelated-histories
  • 1

在合并的时候会需要提交一个merge的说明,是一个交互式的,正常操作即可。

合并成功,分支结果图如下

	A---B---C topic
	          \
    D----------E master
  • 1
  • 2
  • 3
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
  

闽ICP备14008679号