在使用git从远程仓库pull文件到本地时出现 fatal: 拒绝合并无关的历史 报错
经过测试对比 个人理解会报该错的原因 是因为你在从远程仓库pull到本地之前 有以下类似操作
git add xx.docx
git commit -m “doc”
而在你准备push到远程仓库时 因为此时在你本地仓库(ox)有此数据既没有被push上去也没有被del掉 所以此时这个数据被git认为是 无关的历史数据 所以你在这时候选择同步远程仓库的时候他会给你报一个fatal: 拒绝合并无关的历史 这时的解决方法就是让git在检验的时候忽略掉它
git pull ox master --asllow-unrelated-histoies
下面为两次测试对比: 两次只有执行同步远程仓库的先后顺序的差别
(先同步后操作)√
git init
git remote add ox https://github.com/broomcorn-millet/text.git
git pull ox master
remote: Enumerating objects: 16, done.
remote: Counting objects: 100% (16/16), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 16 (delta 1), reused 16 (delta 1), pack-reused 0
展开对象中: 100% (16/16), 完成.
来自 https://github.com/broomcorn-millet/text
- branch master -> FETCH_HEAD
-
[新分支] master -> ox/master
git add aa345b439d4de814!600x600.jpg
git commit -m “ox”
[master 543fdfe] ox
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 aa345b439d4de814!600x600.jpg
[email protected]:~/图片$ git push -u ox master
对象计数中: 3, 完成.
Delta compression using up to 8 threads.
压缩对象中: 100% (3/3), 完成.
写入对象中: 100% (3/3), 70.52 KiB | 7.83 MiB/s, 完成.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/broomcorn-millet/text.git
f992a3a…543fdfe master -> master
分支 ‘master’ 设置为跟踪来自 ‘ox’ 的远程分支 ‘master’。
(先操作后同步)×
git add 不愧.docx
git commit -m “doc”
git remote add ox https://github.com/broomcorn-millet/text.git
git push -u ox master
git pull ox master
warning: 没有共同的提交
remote: Enumerating objects: 16, done.
remote: Counting objects: 100% (16/16), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 16 (delta 1), reused 16 (delta 1), pack-reused 0
展开对象中: 100% (16/16), 完成.
来自 https://github.com/broomcorn-millet/text
- branch master -> FETCH_HEAD
-
[新分支] master -> ox/master
fatal: 拒绝合并无关的历史