Git问题汇总
1.error: cannot lock ref ‘refs/remotes/origin/master’: unable to resolve reference ‘refs/remotes/origin/master’: reference broken
执行git pull 时遇到的问题。
解决方法,
(1) 首先我执行了
1 | git update-ref -d refs/remotes/origin/master |
结果出现了新的问题:error: cannot lock ref ‘refs/remotes/origin/master’: unable to resolve reference ‘refs/remotes/origin/master’: reference broken
(2) 上面方法不行的话,我直接就删除了 .git\refs\remotes\origin 下的master文件,然后重新拉取和提交,然后就解决了问题。
(3) 后来又出现了:Git cannot lock ref ‘HEAD’: unable to resolve reference HEAD,然后我执行了下面的步骤,解决了问题。
1 | ## 删除文件 |
参考文章:
1.git pull时遇到error: cannot lock ref ‘xxx’: ref xxx is at (一个commitID) but expected的解决办法
2.git pull fails “unable to resolve reference” “unable to update local ref”
3.cannot lock ref问题的解决
4.Git cannot lock ref ‘HEAD’: unable to resolve reference HEAD
2.fatal: refusing to merge unrelated histories
在操作后面添加:–allow-unrelated-histories
1 | git pull origin master --allow-unrelated-histories |
参考文章:
【1】.解决Git中fatal: refusing to merge unrelated histories
3.fatal: Authentication failed for ‘’
在命令行中输入git push ,总是弹出权限问题。
用了:git config –system –unset credential.helper 命令,不好使。那就打开:C:\Users\用户名.gitconfig,删除密码管理。
1 | [credential] |
参考文章:
1.fatal: Authentication failed for又不弹出用户名和密码 解决办法
4.git reset more???
执行:
1 | git reset --hard HEAD^ |
告诉我More? More? 我怎么知道More?
改成:git reset –hard “HEAD^” 就可以了。
参考文章:
1.Git常见问题
5.执行git add . 时遇到 warning: You ran ‘git add’ with neither ‘-A (–all)’ or ‘–ignore-removal’
在仓库中删除文件后,试图直接用 git add . 将所有删除工作提交暂存区,结果遇到了报错:
1 | warning: You ran 'git add' with neither '-A (--all)' or '--ignore-removal', |
用 git add –all 可以解决问题。
参考文章:
1.git: git add –ignore-removal & git add –all 区别
6.warning: LF will be replaced by CRLF
这个是在windows系统中必见的一个问题。这个是个警告,告诉你在提交的时候,会自动把CRLF转换为LF,等再linux上就不用在转换了。忍忍就过去了,不是什么大毛病。
我觉得还是关闭这个自动转换比较好,要不在编写shell脚本的时候,总是会出现问题。
1 | ## 全局设置 |
参考文章:
1.Git中的“LF will be replaced by CRLF”警告详解
2.关于git提示“warning: LF will be replaced by CRLF”终极解答
3.Git中的“LF will be replaced by CRLF”警告详解 设置core.autocrlf属性为false,去除警告如下
4.禁止git自动将lf转换成crlf
7.Bad git config file .git/config
执行hexo d的命令时,出现了这个问题:
直接把 .deploy_git 文件删掉就可以了,然后再次执行 hexo d
参考文章:
1.Bad git config file .git/config
2.Git: fatal: bad config file line 1 in .git/config
3.git使用问题:fatal: bad config line 1 in file C:/Users/Administrator/.gitconfig
8.fatal: refusing to merge unrelated histories
慎重执行下面的命令,虽然能解决问题,但是会出现这个冲突,最后会在很多文件中生成: <<<<<<< HEAD 冲突标志符,估计和换行符有关。
1 | git pull origin master --allow-unrelated-histories |
参考文章:
1.解决Git中fatal: refusing to merge unrelated histories
9.出现gun nano界面
提交的时候,出现了冲突,需要输入合并的理由,但是就是不会操作,需要按Ctrl+X然后输入y,然后再按Ctrl+X就可以了。将编辑器改为vim,使用 git config命令
1 | git config --global core.editor "vim" |
参考文章:
1.git提交后出现nano界面,解决方法
2.nano编辑器使用教程
10.raw.githubusercontent.com port 443: Connection refused
在下载和安装nvm的时候,出现了这样的问题,当然也不仅仅是这个库的问题,还有很多关于github的库都和这个有问题。
有人推荐使用switchhousts修改,我这里直接使用了命令行编辑了hosts文件,增加了下面的内容
1 | ## sudo vim /etc/hosts |
参考文章:
1.如何解决类似 curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused 的问题 #10 (这里提供了一个使用switchhosts修改host文件的方法,出现这个问题的原因主要是DNS污染导致的)
11.LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to raw.githubusercontent.com:443
参考文章:
1.SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
12.Your name and email address were configured automatically based
在苹果上提交的时候,出现了下面的问题:
1 | Your name and email address were configured automatically based |
解决方法:键入 git config –global user.name “你的 GitHub 用户名” 与 git config –global user.email “你的 GitHub 用户名对应的 email 地址”。然后再键入 git commit –amend –reset-author 即可。
参考文章:
1.GitHub 笔记 (这里有解决办法和原因)
13.crun: error: invalid active developer path
MacOS 升级到Big Sur之后,就出现了这个问题:crun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
解决方法:
1 | ## 重新安装 |
参考文章:
1.解决MacOS升级后出现xcrun: error: invalid active developer path, missing xcrun的问题
2.Mac OS: xcrun: error: invalid active developer path, missing xcrun (这里提供了不一样到命令:sudo xcode-select –reset)
14.Not possible to fast-forward
本地提交了更改,但是没有先pull,会出现这个问题。但是如果代码有冲突(别人和你修改了同一行代码,导致git不能自动合并),你会发现执行完之后本地版本变成了:develop|REBASE 1/157,类似于这样的,说明rebase失败了,命令会提示哪些文件没有rebase成功,你需要手动将这些冲突合并。等待所有冲突文件修改完成,暂存所有文件。
1 | ## master指的是当前修改的分支,请修改当前你所修改的分支名称(不然会出人命的0.0) |
参考文章:
1.git pull 提示Not possible to fast-forward,无法提交也无法更新 如果依然存在冲突文件,重复步骤3、4、5,直到所有冲突修改完毕就可以了,最后就能正常提交更新了。
2.git pull提示Not possible to fast-forward的解决方法 这个就差了一步,–continue
3.Fatal: Not possible to fast-forward, aborting 两种情形但不同解决方法,基本上也是上面的东西
15.Pulling without specifying how to reconcile divergent branches is discouraged
1 | git config pull.rebase false |
参考文章:
1.Git问题解决:warning: Pulling without specifying how to reconcile divergent branches is discouraged. You
16.Permanently added ‘xxx’ (ECDSA) to the list of known hosts
参考文章:
1.解决SSH登录时出现Warning: Permanently added告警问题
17.unsafe repository To add an exception for this directory, git config –global –add safe.directory
我新装了git之后出现的这个问题
【解决】
出现这个问题的原因,可能就是因为我重装了系统之后,文件及其文件夹的所有者变化了。
(1) 可以直接如下添加安全目录,这样太麻烦了。
1 | ## 直接设置安全目录 |
(2) 也可以使用修改文件夹的所有者的方式,右键文件属性->安全->高级->更改所有者,包括子文件夹,如果文件夹比较多,可能比较慢。
参考文章:
1.Git 提示 fatal: unsafe repository is owned by someone else 错误 修改文件夹所有者
18.no matching host key type found. Their offer: ssh-rsa
在用户文件夹下 ~/.ssh/ 下新建 config 文件,里面填入,windos用户就是另外的用户文件夹了,我这里就不贴了。
1 | Host * |
参考文章:
1.记一次使用git报错,解决Unable to negotiate with **** port 22: no matching host key type found. Their offer: ssh-rsa
2.解决SSH no matching host key type found 问题
19.gitee更新不到最新代码
这个问题真是奇怪,我使用git pull origin master 拉取最新的代码,显示已经更新了,但是实际上本地文件还是没有修改。
【解决方法】
1 | # 重置索引和工作目录 |
参考文章:
1.gitee 更新不到最新代码解决方案
2.git pull 没报错,但是拉下来的代码不是最新更新的 这个没用
20.Host key for github.com has changed and you have requested strict checking
【解决方法】
我在拉取远程仓库的时候,出现了这个问题,我还以为是安装了conda的环境导致的,后来发现不是,在known_hosts里面,github的地址是一个192的地址,我删除了这个地址之后,重新拉取了远程仓库。
1 | # 编辑known_hosts文件,删除github这一列,重新拉取 |
如果在Azure.Devops上也发生了这个问题,那就是同样的道理进行配置就好了。
参考文章:
1.Has GitHub changed his remote host key
21.invalid path
在我在windows上进行切换的时候,出现了问题:“error: invalid path ‘E:\workspace\jeecg-boot/src/main/java/org/jeecg/modules/demo/mapdata/controller/GpsHistoryController.java’”,我明明没有这个 E:\workspace 目录啊,到底是怎么回事呢?我在mac系统上没有问题啊。
1 | # 克隆 |
【尝试方案】
(1)我尝试执行了下面的方法,结果无效。
1 | git config core.protectNTFS false |
(2)将整个仓库的中文改为英文,无效
(3)重新安装了 git 工具,还是无效。
(4)使用 git rm 命令删除文件,结果没有这个路径。
(5)我重新把整个的 .git 文件删除了,然后重新上传了,结果从mac 上传,从windows 上下载,结果还是报错。直接在克隆的时候就报错了。“fatal: unable to checkout working tree
warning: Clone succeeded, but checkout failed.”
最后也克隆不下来,只生成了一个文件夹,和里面的一个 .git 文件夹,其他的什么文件都没有。
【解决方案】
我突然发现了这么一个奇怪的东西,就是在我的仓库里面,出现了这个 E:\wockspace 这个东西,我不记得自己提交过这个东西啊。我记得这是在使用 jeecg-boot 生成代码的时候出现的这个东西,原来在mac上是被隐藏了啊。
使用 rm -rf 删除之后,重新提交就可以了。
1 | rm -rf E:\\workspace\\jeecg-boot |
参考文章:
1.windows10 git 切换分支error: invalid path
2.git checkout master 报错 error: invalid path ‘文件路径‘ 大概意思是说NTFS有个路径保护机制,防止文件系统出错。
3.git - 移除文件以及取消对文件的跟踪
4.windows下git clone后出现invalid path的解决方法 git config –global core.protectNTFS false。虽然是能克隆下来了, 但是因为windows和linux、mac支持的文件命名字符不一样,所以有些文件就会消失,这个望须知
22.Unlink of file
我切换分支的时候,又出现了这个问题。这个问题也让我很纳闷,本来我就已经进行了文件的保存和提交,然后切换分支的时候,就出现了问题。我把idea关掉之后,然后使用命令行:git status,发现竟然有文件被删除了,我只好把文件重新拷贝回来,然后进行 add 重新提交。
参考文章:
1.git错误:Unlink of file ‘xxx’ failed.Should I try again? 原因是git维护管理的代码被其他程序在使用,如IDE(Android Studio等)。解决方法关闭程序IDE或使用到程序代码的应用即可。
23.’credential-manager’ is not a git command
这个问题主要出在了window端,后来我也没有解决,就先这个样子了,没有办法,只能换到了mac上进行了提交和更新,暂时先这个样子吧。
【尝试解决方案】
1.配置 credential.helper
1 | git config --global --unset credential.helper |
参考文章:
1.[已解决] git push 报错:git: ‘credential-manager’ is not a git command. See ‘git –help’.
24.non-fast-forward
参考文章:
1.git解决non-fast-forward冲突
2.解决:git push时出现 hint: Updates were rejected because the tip of your current branch is behind
