2

There are many posts here on Stackoverflow about how to fix your repository when you come across an error like this after doing a git pull:

error: object file .git/objects/48/088f00d90b0d27de65336bb9ed9a75b0cfed33 is empty fatal: loose object 48088f00d90b0d27de65336bb9ed9a75b0cfed33 (stored in .git/objects/48/088f00d90b0d27de65336bb9ed9a75b0cfed33) is corrupt

What I'm curious to know is: what are examples of things that would cause this error to begin with?

Some questions report things like their system rebooting or their battery dying in the middle of a git pull. This interruption causing the issue makes sense.

Then there are other questions who report that the issue repeatedly happening, such as in this post, with no clear indicator as to why.

Community
  • 1
  • 1
sbuck
  • 1,846
  • 4
  • 24
  • 40

1 Answers1

1

These errors should not happen when changes to the Git repository are carried out using the Git client. From the documentation, see Object Storage to learn how Git stores its objects:

  1. Git constructs a header that starts with the type of the object
  2. Git concatenates the header and the original content and then calculates the SHA-1 checksum of that new content
  3. Git compresses the new content with zlib

A corrupt loose object is any object whose state deviates from this design (See also What are the “loose objects” that the Git GUI refers to?).

Besides a system reboot or a dying battery, other reasons include

  • using a buggy third-party implementation of Git
  • manually "cloning" using rsync, scp, or some other external tool without data integrity checks
  • copying and pasting in Windows
  • disk failure
  • sometimes just a blue moon could do it

If you're curious, try this contrived example:

$ git init bad-apple
Initialized empty Git repository in /tmp/bad-apple/.git/

$ cd bad-apple

$ touch README; git add .; git commit -m "Add a transitional fossil"
[master (root-commit) ca3ea96] Add a transitional fossil
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README

# Get the commit object id
$ git rev-parse HEAD
ca3ea9630c0f01afc286589c4072db9c43262d63

# Git tries to help you not shoot yourself in the foot
$ chmod +w .git/objects/ca/3ea9630c0f01afc286589c4072db9c43262d63

# Empty out the commit object file and you broke it
$ truncate .git/objects/ca/3ea9630c0f01afc286589c4072db9c43262d63 --size 0
error: object file .git/objects/ca/3ea9630c0f01afc286589c4072db9c43262d63 is empty
error: object file .git/objects/ca/3ea9630c0f01afc286589c4072db9c43262d63 is empty
fatal: loose object ca3ea9630c0f01afc286589c4072db9c43262d63 (stored in .git/objects/ca/3ea9630c0f01afc286589c4072db9c43262d63) is corrupt
Community
  • 1
  • 1
Ed I
  • 7,008
  • 3
  • 41
  • 50
  • Not using 3rd party Git software, not doing any manual cloning, seeing it on Mac and PCs. Happening too consistently to be a blue moon. Puzzled as to what continues to cause this. Regardless, very useful answer - thank you! – sbuck Nov 07 '14 at 04:34
  • Sounds painful. If it's happening to multiple clients I would suspect the problem is with the remotes. I hope you get to the bottom of it. – Ed I Nov 07 '14 at 04:58
  • How does "copying and pasting in Windows" cause a problem? – Peter Harrison Aug 02 '23 at 13:15