环境
MacBook Pro
Git: 2.21.0
前言
在玩Hugo
的最后一步时,因为我的GitHub
以前就有代码了,所以我先执行了:
git rm -rf --cache *
之后,再按照Hugo
网上的教程去推送代码时,遇到了如下的错误:
yutaodeMacBook-Pro:public yutao$ git push -u origin master
To github.com:b3601993/b3601993.github.io.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:b3601993/b3601993.github.io.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
根据提示,我得执行git pull
。
yutaodeMacBook-Pro:public yutao$ git pull -f origin master
warning: no common commits
remote: Enumerating objects: 45, done.
remote: Counting objects: 100% (45/45), done.
remote: Compressing objects: 100% (23/23), done.
remote: Total 153 (delta 9), reused 45 (delta 9), pack-reused 108
Receiving objects: 100% (153/153), 1.20 MiB | 518.00 KiB/s, done.
Resolving deltas: 100% (17/17), done.
From github.com:b3601993/b3601993.github.io
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
fatal: refusing to merge unrelated histories # 错误在这
这个错误呢,官网有个图,很清晰明了:
![Git](https://i-blog.csdnimg.cn/blog_migrate/f67efa72a4dd5f87463370a54b2f41bd.png)
解决办法
git pull origin master --allow-unrelated-histories
参考地址:https://www.educative.io/edpresso/the-fatal-refusing-to-merge-unrelated-histories-git-error