I have a git object that is corrupted. The size of the file is 0 in the git objects dir.
First a fsck:
git fsck --full
fatal: loose object a35c1489005cca1ffeb3c2d3e4d63988408b6a24 (stored in .git/objects/a3/5c1489005cca1ffeb3c2d3e4d63988408b6a24) is corrupted
Then a ls:
ls -l .git/objects/a3/5c1489005cca1ffeb3c2d3e4d63988408b6a24
----------+ 1 sampath ???????? 0 Sep 13 15:26 .git/objects/a3/5c1489005cca1ffeb3c2d3e4d63988408b6a24
That file doesn't exist on the disk!?
# git cat-file -t a35c1489005cca1ffeb3c2d3e4d63988408b6a24
error: unable to find a35c1489005cca1ffeb3c2d3e4d63988408b6a24
fatal: git cat-file a35c1489005cca1ffeb3c2d3e4d63988408b6a24: bad file
I saw this error first when I tried to do a pull.
I tried removing the file and doing a pull, but that did not work. It complained that the file is missing.
When I removed the file and ran fsck, it showed me a lot of dangling objects
# git fsck --full
broken link from commit 1e5980c224ff19b19ad99dbefed4c7c64c58aee6
to tree a35c1489005cca1ffeb3c2d3e4d63988408b6a24
dangling tree 0401d636a512b208dffd6ac6e153ab0a061f8d5d
dangling blob 58014c0266784a1e3cc1502de82837c5f36c8514
dangling tree 0507fa56260c693cea678eab0343240c5bba06ad
dangling tree 130770880c664a0b0cf5a21d037cbdba7480dc90
I tired going back a few commits and it did not help.
Any pointers on how to recover from this?
The git fsck command checks the connectivity and validity of objects in the git repository. Using this command, users can confirm the integrity of the files in their repository and identify any corrupted objects.
Loose objects are the simpler format. It is simply the compressed data stored in a single file on disk. Every object written to a seperate file.
Looks like a tree is corrupted. If you know your structure around those commits, you could guess what it is. Hopefully you can deduce what files were added or removed. Your blobs and other trees will be dangling as well. If you really want to recover from this and have no other clones of the repo, it's still possible but will involve some time and effort and luck.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With