Github上面的一个仓库很久没有更新了,最近想写点新的东西放上去。结果提示:master and dev are entirely different commit histories.两个分支是两个不同的版本,具有不同的提交历史,想要拉取和提交都被拒绝,找了资料和百度,发现要加一句命令才可以,记下备忘。解决方案如下:

1.git checkout master #切换到要提交代码的分支
2.git pull origin master --allow-unrelated-histories #加上后面这个选项允许不相关历史提交
3.git push origin master #提交到远程分支

NOTE:首先需要pull,发现refusing to merge unrelated histories,因为两个仓库提交历史不一致,无法pull拉取远程信息,所以需要在GIT命令中添加一句代码:--allow-unrelated-histories允许不相关历史进行提交,代码是在git 2.9.2版本发生的,最新的版本需要添加--allow-unrelated-histories (eg:git pull origin master --allow-unrelated-histories)

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐