DEBUG.WIKI
ZgoCloud:多地区部署,按需选节点;日本、美国、香港、德国
V.PS:让项目靠近用户,亚太、欧洲、北美 KVM VPS
晚安云;香港 CN2 ¥15/月

解决 Git 报错 fatal: cannot lock ref unable to resolve reference

分析 Git fetch 时因分支大小写冲突或损坏的 ref 文件报 cannot lock ref 根因,提供 git gc 与清理方案。

问题现象

执行 git fetch 或 git pull 报错:

error: cannot lock ref 'refs/remotes/origin/feature/test': unable to resolve reference
fatal: cannot lock ref 'refs/remotes/origin/feature/test': reference broken

触发根因

  1. 本地 .git/refs/remotes/origin/feature/test 文件内容破损或变成空文件。
  2. 操作系统不区分大小写(macOS/Windows)导致 feature/Test 与 feature/test 冲突。

解决步骤与操作命令

步骤一:清理破损的引用文件

rm -f .git/refs/remotes/origin/feature/test
git prune
git fetch --prune

远端最新指针重新下载,拉取恢复顺畅。