您当前的位置: 首页 >  git

顧棟

暂无认证

  • 0浏览

    0关注

    227博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Git merge 出现 refusing to merge unrelated histories

顧棟 发布时间:2022-02-10 10:02:33 ,浏览量:0

GIT合并不相关的分支 问题

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

	A---B---C topic
	          
    D         master

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

git merge topic

出现报错信息

Could Not Merge topic: refusing to merge unrelated histories 
解决方案

查阅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

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

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

	A---B---C topic
	          \
    D----------E master
关注
打赏
1663402667
查看更多评论
立即登录/注册

微信扫码登录

0.7544s