Git调试:执行git pull --prune时出现无法锁定引用及文件已存在错误
解决git pull --prune时的锁文件错误
问题场景
执行git pull --prune时触发如下错误:
error: could not delete references: cannot lock ref 'refs/remotes/origin/branchname': Unable to create 'C:/develop/repo/.git/refs/remotes/origin/branchname.lock': File exists. Another git process seems to be running in this repository, e.g. an editor opened by 'git commit'. Please make sure all processes are terminated then try again. If it still fails, a git process may have crashed in this repository earlier: remove the file manually to continue. From github.com/repo
且每次执行pull或fetch操作时,都会重复触发批量清理远程已删除分支的流程,完全无法推进。
处理步骤
- 关闭所有关联该仓库的Git进程,包括Git终端窗口、IDE内置Git插件、Git GUI客户端等
- 手动删除报错信息中指定的锁文件:
C:/develop/repo/.git/refs/remotes/origin/branchname.lock - 若大量分支出现同类锁文件问题,可直接进入
.git/refs/remotes/origin/目录,批量删除所有.lock后缀的文件 - 重新执行
git pull --prune,或先单独执行git fetch --prune再执行pull操作
补充排查点
如果删除锁文件后仍报错,检查当前用户对仓库.git目录的读写权限;若权限无问题仍无法解决,可尝试重新克隆仓库(仅作为最后备选方案)。
内容的提问来源于stack exchange,提问作者Kevin
相关产品推荐
相关产品推荐

