Git 拒绝合并不相关的历史记录。什么是“无关历史”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45272492/
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
Git refusing to merge unrelated histories. What is 'unrelated histories'?
提问by Byeongin Yoon
In my local, I made new text file -> git add newfile.txt -> commit -> pull origin master -> ERROR!
在我的本地,我创建了新的文本文件 -> git add newfile.txt -> commit -> pull origin master -> ERROR!
"refusing to merge unrelated histories".
“拒绝合并不相关的历史”。
What is unrelated histories? , what is related histories?
什么是不相关的历史?,什么是相关史料?
回答by Yashar Panahi
I think you have commit in remote repository and when you pull this error happen.
我认为您已在远程存储库中提交,并且当您提取此错误时会发生。
use this command
使用这个命令
git pull origin master --allow-unrelated-histories
git merge origin origin/master
回答by Tasnim Fabiha
When somehow the local .git
subdirectory is lost, the whole project seems to be appeared from nowhere, as all the local changes histories were contained by .git
. Thus, your local changes become unrelated. That is why all the changes are called unrelated histories
then.
当不知何故本地.git
子目录丢失时,整个项目似乎从无处出现,因为所有本地更改历史都包含在.git
. 因此,您的本地更改变得无关紧要。这就是为什么所有更改都被调用的原因unrelated histories
。
In this situation, git merge or pull
request will unable to track where you made changes to add with the remote project. Hence, " refusing to merge unrelated histories"
- error occurs.
在这种情况下,git merge or pull
请求将无法跟踪您在远程项目中添加更改的位置。因此," refusing to merge unrelated histories"
出现 - 错误。
In this situation, if you try to force merge by following commands,
在这种情况下,如果您尝试通过以下命令强制合并,
git pull origin master --allow-unrelated-histories
git pull origin master --allow-unrelated-histories
git merge origin origin/master
git merge origin origin/master
it will create a lot of conflicts, as it is not able to find the history of your local changes.
它会产生很多冲突,因为它无法找到您本地更改的历史记录。
回答by Youngjae
I got this issue when renaming one of repository in GitHub Enterprise, and then making same former named repo as below steps.
我在 GitHub Enterprise 中重命名存储库之一时遇到了这个问题,然后按照以下步骤制作相同的前命名存储库。
- create repo
sample
in remote - clone it to local
- rename remote to
old-sample
- create a new repo named
sample
in remote - try to push it from local
- error occurred.
sample
在远程创建 repo- 克隆到本地
- 将远程重命名为
old-sample
- 创建一个以
sample
远程命名的新仓库 - 尝试从本地推送它
- 错误发生。
Weird thing is that I removed local repo but git tries to clone old one even if I try to clone by newly created repo url. The clone url is just automatically redirected to old one even if the new one is existed in remote. I don't know this cause is from server or local git process.
奇怪的是,我删除了本地 repo,但即使我尝试通过新创建的 repo url 进行克隆,git 也会尝试克隆旧的 repo。即使远程存在新的 url,克隆 url 也会自动重定向到旧的。我不知道这个原因是来自服务器还是本地 git 进程。
For this reason, the error occurs because the git process fails to compare its local commit history to remote history.
出于这个原因,发生错误是因为 git 进程无法将其本地提交历史记录与远程历史记录进行比较。
The unrelated historiescould tell in above situation.
在不相关的历史可以告诉在上述情况。
I ended up to remove renamed old repo in remote and it solved.
我最终在远程删除了重命名的旧仓库并解决了。