最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】git更新时出错:fatal: refusing to merge unrelated histories

Git crifan 6905浏览 0评论

VSCode中去

取消本地的更改

然后去拉取最新代码:

结果出错:

fatal: refusing to merge unrelated histories

然后去终端中试了git命令也是同样结果

➜  ucowsapp git:(master) git pull
fatal: refusing to merge unrelated histories

git pull fatal: refusing to merge unrelated histories

rebase – Git refusing to merge unrelated histories – Stack Overflow

➜  ucowsapp git:(master) git –version
git version 2.11.0 (Apple Git-81)

git – Trying to pull files from my Github repository: "refusing to merge unrelated histories" – Stack Overflow

git无法pull仓库refusing to merge unrelated histories – lindexi_gd的专栏 – 博客频道 – CSDN.NET

然后加上参数就可以了:

➜  ucowsapp git:(master) git pull –allow-unrelated-histories
Auto-merging src/style/index.less
CONFLICT (add/add): Merge conflict in src/style/index.less
Auto-merging src/store/util.js
CONFLICT (add/add): Merge conflict in src/store/util.js
Auto-merging src/store/store.js
CONFLICT (add/add): Merge conflict in src/store/store.js
Auto-merging src/store/actions.js
CONFLICT (add/add): Merge conflict in src/store/actions.js
Auto-merging src/index.js
CONFLICT (add/add): Merge conflict in src/index.js
Auto-merging src/container/main/style.less
CONFLICT (add/add): Merge conflict in src/container/main/style.less
Auto-merging src/container/main/index.js
CONFLICT (add/add): Merge conflict in src/container/main/index.js
Auto-merging src/container/app.js
CONFLICT (add/add): Merge conflict in src/container/app.js
Auto-merging src/components/tab/style.less
CONFLICT (add/add): Merge conflict in src/components/tab/style.less
Auto-merging src/components/tab/index.js
CONFLICT (add/add): Merge conflict in src/components/tab/index.js
Auto-merging src/components/header/style.less
CONFLICT (add/add): Merge conflict in src/components/header/style.less
Auto-merging src/components/header/index.js
CONFLICT (add/add): Merge conflict in src/components/header/index.js
Auto-merging package.json
CONFLICT (add/add): Merge conflict in package.json
Auto-merging .gitignore
CONFLICT (add/add): Merge conflict in .gitignore
Auto-merging .eslintrc
CONFLICT (add/add): Merge conflict in .eslintrc
Automatic merge failed; fix conflicts and then commit the result.

结果上面一堆的CONFLICT

VSCode中也可以看到:

算了,所有的更改都取消掉:

再去拉取,还是出错:

error: You have not concluded your merge (MERGE_HEAD exists).
hint: Please, commit your changes before merging.
fatal: Exiting because of unfinished merge.

去查,如何把抛弃本地所有的修改:

git 抛弃本地修改

git 取消修改,恢复版本 命令大全 – 常兴E站 – 博客频道 – CSDN.NET

git如何删除本地所有未提交的更改 – V2EX

Git – 撤消操作

➜  ucowsapp git:(master) git reset –hard
HEAD is now at c15c694 update files
➜  ucowsapp git:(master) git status
On branch master
Your branch and ‘origin/master’ have diverged,
and have 6 and 3 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)
nothing to commit, working tree clean
➜  ucowsapp git:(master) git pull
fatal: refusing to merge unrelated histories
➜  ucowsapp git:(master)
➜  ucowsapp git:(master) git revert HEAD
[master 4551395] Revert "update files"
3 files changed, 6 insertions(+), 15 deletions(-)
delete mode 100644 .vscode/settings.json

➜  ucowsapp git:(master) git status
On branch master
Your branch and ‘origin/master’ have diverged,
and have 7 and 3 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)
nothing to commit, working tree clean

Your branch and ‘origin/master’ have diverged

git – master branch and ‘origin/master’ have diverged, how to ‘undiverge’ branches’? – Stack Overflow

➜  ucowsapp git:(master) git reset –hard origin/master
HEAD is now at 1fbc0ce update
➜  ucowsapp git:(master) git status
On branch master
Your branch is up-to-date with ‘origin/master’.
nothing to commit, working tree clean

【总结】

最终通过

git reset –hard origin/master

恢复了最干净的,和服务器端一样的代码。

转载请注明:在路上 » 【已解决】git更新时出错:fatal: refusing to merge unrelated histories

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
85 queries in 0.181 seconds, using 22.09MB memory