git Git拒绝在rebase上合并不相关的历史

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37937984/
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:17:14  来源:igfitidea点击:

Git refusing to merge unrelated histories on rebase

gitrebase

提问by Shubham Chaudhary

During git rebase origin/developmentthe following error message is shown from Git:

git rebase origin/development从 Git 显示以下错误消息期间:

fatal: refusing to merge unrelated histories
Error redoing merge 1234deadbeef1234deadbeef

My Git version is 2.9.0. It used to work fine in the previous version.

我的 Git 版本是 2.9.0。它曾经在以前的版本中运行良好。

How can I continue this rebase allowing unrelated histories with the forced flag introduced in the new release?

我怎样才能继续这个 rebase 允许与新版本中引入的强制标志无关的历史?

回答by blue112

The default behavior has changed since Git 2.9:

自 Git 2.9 以来,默认行为发生了变化:

"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-historiesoption to be used in a rare event that merges histories of two projects that started their lives independently.

“git merge”用于允许合并两个默认没有共同基础的分支,这导致创建现有项目的全新历史,然后被毫无戒心的维护者拉取,这允许将不必要的并行历史合并到现有项目中. 该命令已被告知默认情况下不允许这样做,--allow-unrelated-histories在罕见的事件中使用逃生舱口选项,该事件合并了两个独立开始的项目的历史。

See the Git release changelogfor more information.

有关更多信息,请参阅Git 版本更新日志

You can use --allow-unrelated-historiesto force the merge to happen.

您可以使用--allow-unrelated-histories强制合并发生。

回答by adi

In my case, the error was just fatal: refusing to merge unrelated historieson every try, especially the first pull request after remotely adding a Git repository.

就我而言,fatal: refusing to merge unrelated histories每次尝试都会出错,尤其是远程添加 Git 存储库后的第一个拉取请求。

Using the --allow-unrelated-historiesflag worked with a pull request in this way:

使用该--allow-unrelated-histories标志以这种方式处理拉取请求:

git pull origin branchname --allow-unrelated-histories

回答by Ogbonna Vitalis

Try the following command:

尝试以下命令:

git pull origin master --allow-unrelated-histories

This should solve your problem.

这应该可以解决您的问题。

回答by Adithya Bhat

I got this error when I set up a local repository first. Then I went to GitHub and created a new repository. Then I ran

首先设置本地存储库时出现此错误。然后我去了 GitHub 并创建了一个新的存储库。然后我跑了

git remote add origin <repository url>

When I tried to push or pull, I got the same fatal: unrelated_historieserror every time.

当我尝试推或拉时,我fatal: unrelated_histories每次都遇到相同的错误。

Here is how I fixed it:

这是我修复它的方法:

git pull origin master --allow-unrelated-histories
git merge origin origin/master
... add and commit here...
git push origin master

回答by VIKAS KOHLI

For this, enter the command:

为此,输入命令:

git pull origin branchname --allow-unrelated-histories

For example,

例如,

git pull origin master --allow-unrelated-histories

Reference:

参考:

GitHub unrelated histories issue

GitHub 无关的历史记录问题

回答by MJ Montes

git pull origin <branch> --allow-unrelated-histories

You will be routed to a Vim edit window:

您将被路由到 Vim 编辑窗口:

  • Insert commit message
  • Then press Esc(to exit "Insert" mode), then :(colon), then x(small "x") and finally hit Enterto get out of Vim
  • git push --set-upstream origin <branch>
  • 插入提交消息
  • 然后按Esc(退出“插入”模式),然后:(冒号),然后x(小“x”)最后点击Enter退出 Vim
  • git push --set-upstream origin <branch>

回答by Aamir Kalimi

I had the same problem. Try this:

我有同样的问题。尝试这个:

git pull origin master --allow-unrelated-histories 

git push origin master

回答by Daniel petrov

Try git pull --rebase development

尝试 git pull --rebase development

回答by Amir Hossein Ghasemi

For Android Studio and IntelliJ:

对于 Android Studio 和 IntelliJ:

First, commiteverything and resolve any conflicts.

首先,提交所有内容并解决任何冲突。

Then open the terminal from below of IDE and enter:

然后从IDE下面打开终端并输入:

git pull origin master --allow-unrelated-histories

Now you can push.

现在你可以推了。

回答by Aniket Patil

WARNING THIS WILL POTENTIALLY OVERWRITE THE REMOTE REPOSITORY

警告这可能会覆盖远程存储库

This worked for me:

这对我有用:

git push origin master --force