Skip to content

坏对象引用

错误信息

                fatal: 坏对象 HEAD
              

快速摘要

提交 hash, 分支, or 标签你 referenced 做不 exist or 是 corrupted.

为什么发生

  • 提交 hash 是 misspelled or truncated 也短

  • 提交是 garbage collected 之后是 orphaned

  • .git directory 是 corrupted

  • 你 referenced 分支 or 标签那个做不 exist

最小示例

✗ 错误代码
git checkout abc123  # fatal: bad object abc123
✓ 修复代码
git log --oneline  # find the correct hash
git checkout def4567  # correct hash

hash abc123 做不 exist. Use git log 到查找正确提交 hash, 然后 checkout.

如何诊断

  • 验证 hash 使用 git log --oneline | grep <部分-hash>

  • 检查如果分支 or 标签 exists 使用 git 分支 or git 标签

  • 运行 git fsck 到检查仓库 integrity

如何修复

  • Use 正确, 完整 or sufficiently-长提交 hash

  • 如果提交是 orphaned, 检查 git reflog 到查找它

  • 如果仓库是 corrupted, re-克隆从 remote

  • 创建 missing 分支 or 标签如果它应该 exist

如何预防

  • Use git log 到验证提交 hashes 之前 referencing 它们

  • 运行 git fsck periodically 到检查仓库 health

相关资源

相关术语

相关课程

← 返回语言