GIT Fatal:拒绝合并不相关的历史

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40036648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:33:46  来源:igfitidea点击:

GIT Fatal : refusing to merge unrelated histories

gitbitbucket

提问by Mukesh Rawat

I see:

我懂了:

$ git pull origin master
From https://bitbucket.org/tecgenome/chl-v2.0-html
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

How can I avoid or get past that error message?

如何避免或绕过该错误消息?

回答by VonC

Since Git 2.9 (April 2016), you can try:

从 Git 2.9 (April 2016) 开始,您可以尝试:

git pull --allow-unrelated-histories origin master

But check why those branches are no longer common though.
May be there was a force push rewritting allthe history of origin/master.

但是检查为什么这些分支不再常见。
可能是强推改写了所有的历史origin/master

In which case, if you don't have local commits of your own, it is best to reset your branch to the new one:

在这种情况下,如果您没有自己的本地提交,最好将您的分支重置为新的:

git fetch
git reset --hard origin/master

回答by knight2016

I did meet the same issue, and try the command it gets work.

我确实遇到了同样的问题,并尝试使用它开始工作的命令。

git merge abbranch --allow-unrelated-histories

git merge abbranch --allow-unrelated-histories

here we assume that abbranchis unrelated to current branch. Above command merge abbranchto current branch.

这里我们假设这abbranch与当前分支无关。以上命令合并abbranch到当前分支。

回答by Aditya Shrivastava

if you are facing push Recjectedor this issue in android studio you just open your project enable version control integration

如果您在 android studio 中遇到push Recjected或这个问题,您只需打开您的项目启用版本控制集成

and Move to project from android. right click on package --> go to Git --> Add

并从android移动到项目。右键单击包 --> 转到 Git --> 添加

now come on downside click on terminaland follow given below step

现在下行点击终端并按照以下步骤操作

 git remote add origin <repository url>

    git clone <repository url>
    git pull origin master --allow-unrelated-histories
    git merge origin origin/master
    ... add and commit here...
    git push origin master