git fatal 拒绝合并无关的历史
|Word count:506|Reading time:2min|Post View:
场景
最近学习前端,所以在电脑上创建了jslearn
的项目来练习,在公司时用win学习,在家用mac,因为学习的同时也记录了笔记,于是就想用git做一下同步,首先在win电脑上创建git仓库,并将代码同步到github,然后在mac上的learn也创建git仓库,并将仓库地址指向同一个,此时,使用git pull
会提示如下错误:
1 2 3 4
| git pull origin main 来自 https://github.com/tvzr/jslearn * branch main -> FETCH_HEAD fatal: 拒绝合并无关的历史
|
原因
本地初始化的项目 与 github 版本不一致, 导致无法提交
解决办法
只需要加个--allow-unrelated-histories
参数即可。
1 2 3 4 5 6 7 8 9 10 11 12 13
| git pull origin main --allow-unrelated-histories 来自 https://github.com/tvzr/jslearn * branch main -> FETCH_HEAD Merge made by the 'ort' strategy. README.md | 1 + 匿名自执行函数.html | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 对象.html | 40 ++++++++++++++++++++++++++++++++++++++++ 逻辑中断.html | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 142 insertions(+) create mode 100644 README.md create mode 100644 匿名自执行函数.html create mode 100644 对象.html create mode 100644 逻辑中断.html
|
附加
有时候,推送代码的时候还会提示如下:
1 2 3 4 5 6 7 8 9 10 11 12
| git push -u origin master 枚举对象中: 9, 完成. 对象计数中: 100% (9/9), 完成. 使用 8 个线程进行压缩 压缩对象中: 100% (6/6), 完成. 写入对象中: 100% (6/6), 1.27 KiB | 1.27 MiB/s, 完成. 总共 6(差异 3),复用 0(差异 0),包复用 0 remote: Resolving deltas: 100% (3/3), completed with 3 local objects. remote: fatal error in commit_refs To https://github.com/tvzr/hexo-blog.git ! [remote rejected] master -> master (failure) error: 无法推送一些引用到 'https://github.com/tvzr/hexo-blog.git'
|
解决办法:
方法一
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| git checkout -b "back_master"
git branch -D master
git pull origin master
git fetch --all
git checkout master
git merge back_master
git branch -D back_master
git push origin master
|
方法二
1
| git push -f origin master
|