【问题标题】:fatal: refusing to merge unrelated histories after adding git remote致命:添加 git remote 后拒绝合并不相关的历史记录
【发布时间】:2018-10-11 04:06:54
【问题描述】:

我已将远程存储库添加到我正在使用的文件夹中:

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

【问题讨论】:

标签: git github


【解决方案1】:

您需要先resetcommit 进行更改:

git reset --hard

或:

git commit -m "saving changes..."

那么你可以这样做:

git pull origin master --allow-unrelated-histories

【讨论】:

  • 我遇到了同样的问题,下面的命令解决了。 git pull origin master --allow-unrelated-histories 我创建了一个 github 存储库(提交了一个默认文件),然后我创建了一个本地存储库。因此,repos(远程和本地)独立启动并具有不同的内容。这就是为什么 --allow-unrelated-histories 是必要的。恕我直言,这个问题必须关闭。
  • 我有一个烦人的fatal: refusing to merge unrelated histories
猜你喜欢
  • 2017-01-09
  • 2017-02-23
  • 2017-09-02
  • 2017-12-29
  • 2020-10-03
  • 2016-10-22
  • 2020-08-28
  • 1970-01-01
  • 2018-11-06
相关资源
最近更新 更多