Fatal refusing to merge unrelated histories что делать

How to fix «refusing to merge unrelated histories» when uploading project to github?

I have installed Github desktop and git on windows machine, I got a github account and created a dummy repository.

When I intend to upload my package through git bash command line, it fails with error: fatal: refusing to merge unrelated histories

I used several ways to overcome this issues by using existing solution from this community, but still didn’t fix the problem. Does anyone know any trick of working this problem? How can I upload my projects to github successfully?

3 Answers 3

git log output (1st is GitHub repo, 2nd is local):

PS Funny, I never noticed that the default initial commit message from GitHub is Initial Commit, whereas the local one is Initial commit (lowercase). I think I’ll send that question in to Jack Handy.

Be sure to replace /path/to/my/repo with path to your repo directory(e.g. C:\Users\jvrat\Documents\MSPC ), and with URL to your remote repo (e.g. https://github.com/username/repo_name.git ).

The first step is to init git inside your local project directory:

Files added to your repo are tracked now. If you want to commit all the changes you made to the files you added you just need to

These all resides on your local git repo. To connect your local repo to a remote one you have to issue another command:

‘origin’ and the following URL represent remote name and its URL. You are now able to push your local changes to your origin repo via

which is in your case

because for now you just have a master branch.

You can check the status of your local repo and its connected remote repo via

Источник

Git отказывается объединять несвязанные истории при ребазе

Во git rebase origin/development время следующего сообщения об ошибке отображается из Git:

Моя версия Git 2.9.0. Раньше нормально работал в предыдущей версии.

Как я могу продолжить эту перебазирование, разрешив несвязанные истории с принудительным флагом, введенным в новом выпуске?

Поведение по умолчанию изменилось с Git 2.9:

Смотрите журнал изменений Git для получения дополнительной информации.

В моем случае ошибка была только fatal: refusing to merge unrelated histories при каждой попытке, особенно при первом удаленном запросе после удаленного добавления Git-репозитория.

Попробуйте следующую команду:

Это должно решить вашу проблему.

Я получил эту ошибку, когда я сначала установил локальный репозиторий. Затем я пошел на GitHub и создал новый репозиторий. Потом я побежал

Когда я пытался толкать или тянуть, я fatal: unrelated_histories каждый раз получал одну и ту же ошибку.

Вот как я это исправил:

Для этого введите команду:

Вы будете перенаправлены в окно редактирования Vim:

У меня такая же проблема. Попробуй это:

Для Android Studio и IntelliJ:

Во-первых, совершайте все и разрешайте любые конфликты.

Затем откройте терминал снизу IDE и введите:

Теперь вы можете нажать.

ВНИМАНИЕ, ЭТО ПОТЕНЦИАЛЬНО ЗАПОЛНИТ ДИСТАНЦИОННОЕ ХРАНИЛИЩЕ

Это сработало для меня:

Поскольку все остальные ответы на самом деле не отвечают на вопрос, вот решение, вдохновленное этим ответом на связанный вопрос.

Итак, вы получаете свою ошибку, выполняя git rebase :

Эта ошибка на самом деле не отменяет ребаз, но вы сейчас находитесь в середине:

Теперь вы можете выполнить слияние вручную. Узнайте родительские коммиты исходного коммита слияния:

Выясните, какой из двух родителей слияния является тем, который был слит с текущим (возможно, вторым, проверьте с помощью git log 222222222 ), а затем выполните слияние вручную, скопировав сообщение коммита исходного коммита слияния:

У меня такая же проблема. Проблема удаленная, что-то мешало этому.

Сначала я создал локальный репозиторий. Я добавил LICENSE и README.md файл в мой локальный и совершил.

Так что теперь, когда я побежал

Теперь, чтобы преодолеть это, я сделал

Что привело к следующей ошибке:

Я удалил удаленный репозиторий и создал новый (я думаю, что только удаление файла README могло бы работать), и после этого сработало следующее:

Теперь будут некоторые конфликты, которые мы должны решить вручную. После этого просто передайте код и нажмите его.

Вы создали новый репозиторий, добавили в него несколько коммитов, и теперь вы пытаетесь извлечь из удаленного репозитория, который уже имеет некоторые свои коммиты. Git также выдаст ошибку в этом случае, так как он понятия не имеет, как связаны два проекта.

РЕШЕНИЕ

Я тоже боролся с этим, но мне удалось найти обходной путь.

Когда вы столкнетесь с ошибкой выше, просто выберите команду merge и затем продолжите ребазирование:

Сначала перенесите удаленные изменения в локальную систему, используя следующую команду:

** бранчаме мастер в моем случае.

Когда команда pull выполнена, возникает конфликт. Вы должны решить конфликты. Я использую Android Studio для разрешения конфликтов. Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

Когда конфликты решены, слияние завершено!

Теперь вы можете спокойно нажимать.

Я только что сделал

При этом git pull я получил это сообщение fatal: refusing to merge unrelated histories для модуля репо, где я некоторое время не обновлял локальную копию.

Я запустил эту команду, чтобы обновить локальную версию от источника. Я просто хотел получить последние новости от удаленного и не нуждался в локальных изменениях.

Это исправило это в моем случае.

Итак, мой обычный рабочий процесс ребазирования выглядит следующим образом (но, пожалуйста, имейте в виду, что вы не должны использовать ребаз в ветвях, которые вы не единственный комитет. Для таких ветвей используйте просто слияние и разрешение конфликтов, если применимо):

Как я уже упоминал, имейте в виду, что rebase манипулирует историей git, что обычно плохо. Тем не менее, это можно сделать на ветках, где никто больше не берет на себя обязательства. Для того, чтобы ветки могли работать с другими разработчиками, используйте другую стратегию слияния, такую ​​как слияние, сквош или вишневый кир. Итак, другими словами: Rebase не должен быть вашим инструментом для распределенной разработки. Это прекрасно работает для вас, если вы единственный, кто работает с этим хранилищем.

Мы используем функцию ветки стратегии. В этом я обычно использую rebase для получения «обновлений» от других разработчиков, которые происходили в это время в основной ветке. Это уменьшает размер коммитов, которые видны в запросе на получение. Поэтому рецензенту кода легче увидеть мои изменения, сделанные в этой ветви функций.

Источник

Git refusing to merge unrelated histories on rebase

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

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

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

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

25 Answers 25

The default behavior has changed since Git 2.9:

See the Git release changelog for more information.

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

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

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

Try the following command:

This should solve your problem.

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

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

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

Here is how I fixed it:

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

For this, enter the command:

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

You will be routed to a Vim edit window:

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

I ran this command and issue got resolved.

Check out this page for more info.

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

I had the same problem. Try this:

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

1. Solve the problem

Run one of the below Commands ( earlier it was master now its main) as per the scenario

2. Meaning

The “fatal: refusing to merge unrelated histories” Git error occurs when two unrelated projects are merged (i.e., projects that are not aware of each other’s existence and have mismatching commit 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.

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

References

More on StackOverflow

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

For Android Studio and IntelliJ:

First, commit everything and resolve any conflicts.

Then open the terminal from below of IDE and enter:

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

Since all the other answers are not actually answering the question, here is a solution inspired by this answer on a related question.

So you get your error doing git rebase :

This error doesn’t actually cancel the rebase, but you are now in the middle of it:

So you can now do the merge by hand. Find out the parent commits of the original merge commit:

Find out which of the two merge parents is the one that was merged into the current one (probably the second one, verify with git log 222222222 ), and then do the merge by hand, copying the commit message of the original merge commit:

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

WARNING THIS WILL POTENTIALLY OVERWRITE THE REMOTE REPOSITORY

This worked for me:

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

Firstly pull the remote changes to your local using the following command:

** branchname is master in my case.

When the pull command done, conflict occurs. You should solve the conflicts. I use Android Studio to solve conflicts. Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

When conflicts solved, merge is done!

Now you can safely push.

I had the same problem. The problem is remote had something preventing this.

I first created a local repository. I added a LICENSE and README.md file to my local and committed.

Then I wanted a remote repository so I created one on GitHub. Here I made a mistake of checking «Initialize this repository with a README», which created a README.md in remote too.

Now to overcome this I did

Which resulted in the below error:

I removed the remote repository and created a new (I think only removing file README could have worked) and after that the below worked:

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

Now there would be some conflicts which we have to solve manually. After that just commit the code and push it.

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

I copied all the files on my desktop repository to another folder and then deleted the folder.

Then I clone the repo again because it is a new project.

When I copied my files again and push it worked like charm.

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

I ran this command just to refresh local from origin. I just wanted latest from remote and didn’t need any local changes.

This fixed it in my case.

I struggled with this as well, but I managed to find a workaround.

When you run into the error above, just cherry-pick the merge commit and then continue the rebase:

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

For Googlers:

Now the local and remote will have «related histories» and will merge or rebase happily.

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

The error is resolved by toggling the allow-unrelated-histories switch. After a git pull or git merge command, add the following tag:

After then may be you will get conflict. So resolved the conflict and commit it. It’s work for me.

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

For my case I wanted to merge unrelated history branch to my current:

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

The most voted answer doesn’t solve this question, which is in the context of rebasing.

The only way to synchronize the two diverged branches is to merge them back together, resulting in an extra merge commit and two sets of commits that contain the same changes (the original ones, and the ones from your rebased branch). Needless to say, this is a very confusing situation.

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

So, my usual rebase workflow looks like following (but please keep in mind, that you should not use rebase on branches, which you are not the only one committee. For such branches, use simply merge and resolve conflicts, if applicable):

As I already mentioned, keep in mind, that rebase manipulates the git history, that is usually a bad thing. However, it’s possible to do that on branches, where no one else commits to. In order to keep the branch pull-able for the other developers, use another merge strategy like merge itself, squash or cherrypick. So, in other words: Rebase shouldn’t be your tool on distributed development. It works fine for you if you are the only one who works on this repository.

We use the feature branch strategy. In this, I usually use rebase in order to get the «updates» from the other developers, that happened in the meantime on the master branch. Doing so, it reduces the size of commits that are visible in a pull request. Therefore, it makes it easier for the code reviewer to see my changes made in this feature branch.

Источник

fatal: refusing to merge unrelated histories #61

Comments

tarmo888 commented Aug 16, 2017 •

Steps to reproduce:

The text was updated successfully, but these errors were encountered:

w00fz commented Aug 16, 2017

tarmo888 commented Aug 16, 2017 •

I can reproduce this again by:

tarmo888 commented Aug 16, 2017

commit 3f0710cd4a6b4e5e6accc369daa051cebe8d314d
Merge: e137da7 84d8a85
Date: Wed Aug 16 17:50:21 2017 +0300
Merge branch ‘master’ of https://bitbucket.org/tarmo888/grav-copy

commit 84d8a8580203c131a326988cd8db3e1a4b85e347
Date: Wed Aug 16 14:38:41 2017 +0000
README.md created online with Bitbucket

commit e137da72ed33169b4294efc04be1cf11890e73ff
Date: Wed Aug 16 17:38:06 2017 +0300
(Grav GitSync) Automatic Commit from tarmo888

tarmo888 commented Aug 17, 2017

Order of the commits doesn’t matter either. Still causes the same error until I manually merge.

commit 258026887d61824745bf15e5252b011ddcb5837d
Merge: 8699435 db03608
Date: Thu Aug 17 17:07:34 2017 +0300
Merge branch ‘master’ of https://bitbucket.org/tarmo888/grav-copy

commit 8699435a2358f746276bfe21dd746f00bd56416a
Date: Thu Aug 17 17:06:47 2017 +0300
(Grav GitSync) Automatic Commit from test

commit db036089bdfac73d539b50bb8b2eb396a681bc19
Date: Thu Aug 17 14:05:06 2017 +0000
README.md created online with Bitbucket

Tested with Grav v1.3.1, Grav v1.3.2, Git Sync 1.0.3 and Git Sync 1.0.4

w00fz commented Aug 25, 2018

I’m not sure how unrelated history gets in there if you say it’s a brand new repository. Have you tried with another new repo?

tarmo888 commented Aug 25, 2018

I don’t have time to test it, but it seems that Bitbucket has changed their repository creation flow and README.md is not added anymore, so I am guessing it is not an issue anymore.

JOduMonT commented Mar 16, 2020

w00fz commented Mar 16, 2020

You might need to update git

JOduMonT commented Mar 16, 2020

You might need to update git

git version 2.17.1
from Ubuntu 18.04LTS
but anyway it works now 🙂

JOduMonT commented Mar 16, 2020

RCheesley commented Apr 1, 2020 •

Set up Github repo and Gitsync per usual, but kept on getting the error above.

Git version 2.17.1
Ubuntu 18.04 LTS
Digital Ocean droplet

w00fz commented Jul 17, 2020

Hey everyone, I finally got to the bottom of this issue and it appears a regression was introduced where the method returning the git version would always return true instead of the actual version.

Because the version check is necessary to ensure certain git features get enabled (like allow-unrelated-histories ), the regression would prevent that from happening.

I have now fixed this and @paulhibbitts kindly helped testing this confirming it’s fine. A new release v2.1.1 is out and you shouldn’t be needing manually running the command from terminal anymore, as long as your git version is > 2.9.0 (which is fairly old now).

Thank you everyone for helping determining what the issue was and helping each other with workarounds!

Источник

Trying to pull files from my Github repository: «refusing to merge unrelated histories»

I’m learning git, and I’m following the Git community book.

Previously (long time ago) I made a public repository on Github, with some files. Now I set up a local Git repository on my current computer, and committed some files. Then I added a remote pointing to my Github page:

That seemed to be successful:

Now I want to download the files from my Github repo to my computer. I did this:

However, I don’t see any new files in my local directory. How can I get them?

I also tried to do this:

BTW, locally I’m on master branch (there are no other branches):

8 Answers 8

Like max630 commented, or as explained here Git refusing to merge unrelated histories

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

Resolve conflict, then

Fatal refusing to merge unrelated histories что делать. Смотреть фото Fatal refusing to merge unrelated histories что делать. Смотреть картинку Fatal refusing to merge unrelated histories что делать. Картинка про Fatal refusing to merge unrelated histories что делать. Фото Fatal refusing to merge unrelated histories что делать

When you have a situation like this where you started with a local repository, and want to make a remote on GitHub to share your work with, there is something to watch out for.

When you create the new online repository, there’s an option «Initialize this repository with a README». If you read the fine print, it says «Skip this step if you’re importing an existing repository.»

You may have checked that box. Or similarly, you made an add/commit online before you attempted an initial push. What happens is you create a unique commit history in each place and they can’t be reconciled without the special allowance mentioned in Nevermore’s answer (because git doesn’t want you to operate that way). You can follow some of the advice mentioned here, or more simply just don’t check that option next time you want to link some local files to a brand new remote; keeping the remote clean for that initial push.

Reference: my first experience with git + hub was to run into this same problem and do a lot of learning to understand what had happened and why.

Источник

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *