How to deal with Git “Could not read” error

On a “broken link” message, you could follow the GitFaq recommendations:

  • back up all your state so that anything you do is re-doable if you corrupt things more!
  • explode any corrupt pack-files
    • See “man git-unpack-objects“, and in particular the “-r” flag.
      Also, please realize that it only unpacks objects that aren’t already available, so you need to move the pack-file away from its normal location first (otherwise git-unpack-objects will find all objects that are in the pack-file in the pack-file itself, and not unpack anything at all)
  • replace any broken and/or missing objects
    • This is the challenging part.
      Sometimes (hopefully often!) you can find the missing objects in other copies of the repositories.
      At other times, you may need to try to find the data some other way (for example, maybe your checked-out copy contains the file content that when hashed will be the missing object?).
  • make sure everything is happy with “git fsck --full
  • repack everything to get back to an efficient state again

Notes:

Update July 2016 (7 years laters), with Git 2.10 soon to be released, you now have:

git fsck --name-objects

It helps naming the origin of those broken links

See “How to fix git error broken link from tree to tree?” for more.

Leave a Comment