“拒绝合并不相关的历史”拉到恢复的存储库时失败 [英] "refusing to merge unrelated histories" failure while pulling to recovered repository
问题描述
我想出了一个关于git push的问题。
它以前成功运行,但这次失败。
一开始,我在我的主人中MINGW64 /d/javasoft/apache-tomcat-7.0.70/webapps/MyNote(master)
,然后,
git remote add origin
,但它会提示 fatal:remote origin已存在。
git remote rm origin
(有人告诉我),没关系。 git remote add origin https://github.com/ *** / ***。git
再次。然后,我使用 git push -u origin master
(我试过 git push origin master
,但之前由于某种原因,我丢失了本地整个 .git
,所以我猜可能是第一次推送,我应该添加 -u
)。但是,它提示错误:未能将一些文件推送到'https://github.com/***/***.git'
push
之前,有人告诉我应该使用 git pull origin master
,并且我做到了。但是,它警告:致命:拒绝合并不相关的历史记录
。
然后你出于某种原因丢失了你的本地.git子目录 - 它包含你从 1
到<$ c的所有历史记录$ C> 2 。你设法恢复当前状态。
但现在它没有任何历史 - 看起来整个项目已经出现无处不在。如果你要求git合并它们,它就不能说你的更改在哪里,所以它可以将它们添加到远程项目中,据我所知它只会报告大量的添加/添加冲突。
你现在应该做的是现在是从已经克隆项目的远程历史记录中找回那个提交 1
(我假设你之后没有拉,如果你这样做,那么你应该寻找最后的提交)。然后,你应该修改你的历史记录,以便从该提交1开始,然后git将能够正确合并(例如用拉)。
因此,步骤假设您现在处于未恢复的提交状态):
1
你已经克隆了一些 1?
,根据提交时间为例
git diff _1?_ HEAD
,并仔细阅读,确保差异仅包含您所做的修改。如果它包含更多,那么你应该选择了一些错误的 1?
并且需要调整它并重复这一步
1
,你应该让它成为你的父母,做 git --reset --soft _1 _
,然后 git commit
。
现在看起来您已经从 1
克隆过,然后用所有更改进行了一次提交。您的中间历史记录无论如何都会丢失您的旧版 .git
目录,但现在您可以运行 git pull
- 它会合并正确。
I come up with a problem about git push.
It worked successfully before, but failed this time.
In the beginning, I am in my master MINGW64 /d/javasoft/apache-tomcat-7.0.70/webapps/MyNote (master)
, and then,
- I use
git remote add origin
to relate my romote origin, but it alerts thatfatal: remote origin already exists.
- then, I use
git remote rm origin
(Someone told me to), it's ok. - then, I use
git remote add origin https://github.com/***/***.git
again. It's ok. - then, I use
git push -u origin master
( I triedgit push origin master
, but I lost my local whole.git
for some reason before, so I guess it may be the first time to push, and I should add-u
). BUT, it alertserror: failed to push some refs to 'https://github.com/***/***.git'
- then, someone told me that I should use
git pull origin master
before I usepush
, and I did as it. BUT, it alerted:fatal: refusing to merge unrelated histories
. - I found some answers in Git refusing to merge unrelated histories , but it seemed that it didn't work. In my issue, it alerted
fatal: Couldn't find remote ref –allow-unrelated-histories
really don't know how to do...just want to push..
This cannot be answered shortly.
Warning: You should not use the –allow-unrelated-histories
flag unless you know what is unrelated history and are sure you need it. The check was introduced just to prevent disasters when people merge unrelated projects by mistake.
As far as I understand, in your case has happened the following:
You have cloned a project at some point 1
, and made some development to point 2
. Meanwhile, project has evolved to some point 3
.
Then you for some reason lost your local .git subdirectory - which contained all your history from 1
to 2
. You managed to restore the current state though.
But now it does not have any history - it looks like the whole project has appeared out of nowhere. If you ask git to merge them it will not be able to say where is your changes, so it can add them to remote project, as far as I understand it will just report massive add/add conflicts.
What you should do now is to find back that commit 1
from the remote history where you have cloned the project (I assume you did not pull after that, if you did then you should instead look for the last commit you have pulled). Then you should modify your history so that is starts from that commit 1, then git will be able to merge correctly (with pull for example).
So, the steps (assuming you are now in your restored commit without history):
- estimate where is the commit
1
you have cloned from as some1?
, based on commit time for example - run
git diff _1?_..HEAD
, and read carefully, make sure that the difference contains only edits which you have made. If it contains more then you should have picked a bit wrong1?
and need to adjust it and repeat this step - after you have found the commit
1
, you should make it your parent, dogit --reset --soft _1_
, thengit commit
.
Now it looks like you have cloned from 1
, then made one commit with all your changes. Your intermediate history is lost anyway with your older .git
directory, but now you can run your git pull
- it will merge correctly.
这篇关于“拒绝合并不相关的历史”拉到恢复的存储库时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!