ENOENT
git
data_error
ai_generated
partial
错误:无法从对象数据库读取对象 <hash>:没有那个文件或目录
error: failed to read object <hash> from the object database: No such file or directory
ID: git/error-failed-to-read-object-from-odb
70%修复率
85%置信度
1证据数
2023-11-08首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| git 2.28.0 | active | — | — | — |
| git 2.35.0 | active | — | — | — |
| git 2.45.0 | active | — | — | — |
根因分析
所需的 Git 对象(提交、树或 blob)在 .git/objects 目录中缺失,通常是由于仓库损坏、克隆不完整或垃圾回收失败。
English
A required Git object (commit, tree, or blob) is missing from the .git/objects directory, often due to repository corruption, incomplete clone, or a failed garbage collection.
官方文档
https://git-scm.com/docs/git-fsck解决方案
-
git fetch origin refs/heads/*:refs/remotes/origin/* # Fetch all branches from remote to potentially restore missing objects if they exist on the remote
-
git cat-file -p <hash> 2>/dev/null || (cd /path/to/backup && git cat-file -p <hash>) # Check if object exists in a backup repo; if so, copy the object file to .git/objects/ab/ directory using the hash prefix
无效尝试
常见但无效的做法:
-
85% 失败
Running git gc --aggressive without first recovering missing objects can permanently delete unreachable objects, making recovery impossible.
-
60% 失败
Using git fsck --lost-found may find dangling objects but does not restore missing referenced objects; it just lists them.