You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Git:如何定位克隆时出现偏移错误的文件?

Fixing "fatal: pack has bad object at offset X: inflate returned -5" Error

Alright, let's walk through solving this issue step by step. First, let's clarify why your initial git show :289293315 command didn't work: that number is an offset in the pack file, not a Git object SHA-1 hash. Git doesn't recognize offsets as valid object references, so we need to translate that offset to an actual object ID first.

Step 1: Locate the problematic pack file

When cloning fails mid-process, Git leaves behind partial pack files in your local repo's .git/objects/pack/ directory. Head there and look for the most recently modified .pack file (it'll have a name like pack-abc123def456.pack).

Step 2: Map the offset to a Git object SHA

Use Git's built-in git verify-pack tool to find which object corresponds to that offset. Run this command in your repo root:

git verify-pack -v .git/objects/pack/pack-YOURPACKNAME.pack | grep 289293315

This will output a line with the object's SHA-1 hash, type (blob, tree, commit), size, and other metadata. For example:

a1b2c3d4e5f67890abcdef1234567890abcdef12 blob   12345 289293315 123456

Grab that SHA (the first string in the line).

Step 3: Identify the file associated with the object

Once you have the SHA, you can investigate what it is:

  • Check the object type:
    git cat-file -t a1b2c3d4e5f67890abcdef1234567890abcdef12
    
  • If it's a blob (file content), view its content with:
    git cat-file -p a1b2c3d4e5f67890abcdef1234567890abcdef12
    
  • To find the file path linked to this object (if the repo is partially cloned), try:
    git rev-list --objects --all | grep a1b2c3d4e5f67890abcdef1234567890abcdef12
    
    If that fails, run git fsck --full to get more details about the corrupted object.

Step 4: Fix the issue

Now that you know which object is broken, here are the most common fixes:

Option 1: Retry cloning with workarounds

The error often happens due to an interrupted download or corrupted pack file. Try:

  • Delete the incomplete local repo entirely, then clone again with a shallow clone first (to avoid downloading the full problematic pack at once):
    git clone --depth 1 https://your-repo-url.git
    cd your-repo-name
    git fetch --unshallow
    
  • If shallow cloning doesn't work, try cloning with --no-single-branch to pull all branches separately, or add --verbose to get more download details.

Option 2: Fetch the corrupted object from another source

If you have another working clone of the same repo, you can pull the missing object into your broken repo:

  1. In the working repo, run git bundle create fix.bundle a1b2c3d4e5f67890abcdef1234567890abcdef12
  2. Copy fix.bundle to the broken repo's directory
  3. In the broken repo, run git fetch fix.bundle

Option 3: Ask the repo administrator to fix the remote

If the pack file is corrupted on the remote server, you'll need to reach out to the repo owner. They can:

  • Run git fsck --full on the remote repo to confirm corrupted objects
  • Regenerate pack files with git repack -a -d
  • Restore the corrupted object from a backup

内容的提问来源于stack exchange,提问作者Zenoo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:37:44