在添加Git远程后出现"fatal: refusing to merge unrelated histories"错误

15

我已经将一个远程仓库添加到我正在使用的文件夹中:

git remote add origin https://github.com/<username>/<repo>.git

如果我输入:

git pull origin master

我理解为:

From https://github.com/<username>/<repo>
    * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

我也尝试过:

git pull origin master --allow-unrelated-histories

但是我得到:

From https://github.com/...
    * branch            master     -> FETCH_HEAD
error: Your local changes to the following files would be overwritten by merge:
    <files>
Please commit your changes or stash them before you merge.
Aborting

你要开始新的代码库吗? - max630
关于第二个错误:https://dev59.com/T1sW5IYBdhLWcg3wDzrs - max630
从技术上讲是的,因为它没有找到我正在工作的存储库。所以我输入了以下内容:git remote add origin https://github.co/username/xxxxx.git - ramab01
可能是What does "would be overwritten by merge" mean?的重复问题。 - phd
git pull origin master --allow-unrelated-histories 请参见此处 https://dev59.com/ploU5IYBdhLWcg3wAjYs - Bhargav Variya
1个回答

54

您需要先执行resetcommit操作以提交更改:

git reset --hard
或:
git commit -m "saving changes..."

然后你可以执行:

git pull origin master --allow-unrelated-histories

2
我曾遇到同样的问题,下面的命令解决了它。
git pull origin master --allow-unrelated-histories我创建了一个 GitHub 仓库(提交了一个默认文件),然后创建了一个本地仓库。因此,这些仓库(远程和本地)开始是独立的,内容也不同。这就是为什么需要--allow-unrelated-histories。在我看来,这些问题必须被关闭。
- Cláudio
我遇到了一个烦人的 fatal: refusing to merge unrelated histories 错误。 - Ced

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接