Because I've been rsyncing my Git repository between various places, I'm now stuck with a broken Git repository. When I do git log
I get a correct history, but when I do git status
I get
fatal: unable to read 563e4c9abcd4114e08255db989f0f53426bdeff7
So after some searching around I tried git fsck
:
Checking object directories: 100% (256/256), done.
missing blob 33244941016301570dccdcdc95e543910109d0a8
dangling blob 59f44441e6437ebc4d40182eb8a10d3e07fe367b
missing blob 5dc8ab1804acb58fc658bcd6152fbb246290c8ae
dangling blob 698c775f2599fad3d09906dead4dc67743a984bd
dangling blob 922003b8433bcad6ce9778a37628d738faa26389
dangling blob c33c0528bfee55b04d99de4580da49de4413329b
dangling blob e5107c118bde0edbe5dfb994cb6a50d235c3f06b
dangling blob 437573e539572454cb868ca5a0f5074b96d777ac
missing blob 468d1856336eaa1ce8006f38ce779c0d997c8d48
dangling blob 6fc9c88708d7d5ca455e68781472bdea119997eb
dangling blob 7225d0147fa566369ba3024324b527a7adeac094
dangling blob bb8125d15579fcf37925f09cd1883b15272f9f0d
missing blob c8095f49253ac3787a6f86943160eda2c78a6a28
dangling blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
dangling blob 0bdaed084e15add987ef86fe84f435d085475995
dangling blob 36ee13c9b334da090ea6b194606df8a2852b3b3a
missing blob 563e4c9abcd4114e08255db989f0f53426bdeff7 <= the one which results in the fatal error.
dangling blob 84f2f2a9d1d051e6418a787ca90e75446f712866
dangling blob c636d85269838efecbb496eda5a8cfd8ec753d69
dangling blob cb7a8494bfc86e894c0c6e268308ddc1dd6d713c
dangling blob d166fff9e1c85ab9f0f4f620119181c5f76c2a53
dangling blob d3b6f194df857412481a318d4275faeb6689e4a0
missing blob db9a6744bc0df03cf685296695bea6324f23e0ac
dangling blob def6a6a18457989c7d18825c7c1bbfeefc8b261d
and about 20 more..
And from here I'm kind of lost. I read something about running git reflog expire --expire=now --all
, but that doesn't do anything for me.
All the files in my repository are still present and safely backed up, so that's not a problem. I would like to get my repository history back though. What steps can I take from this point?
I got a "missing blob" after trying to fix "object file is empty" error (actually I ended up with object file .git/objects/f7/880aa1d1a76bfff73f3d602e15b4bc829d6a07
removed from the file system).
In order to solve the issue I followed these steps:
Use the Bash script found here in order to detect a commit containing this missing blob. Put it in the repository's root directory with the find.sh
name:
#!/bin/sh
obj_name="$1"
shift
git log "$@" --pretty=format:'%T %h %s' \
| while read tree commit subject ; do
if git ls-tree -r $tree | grep -q "$obj_name" ; then
echo $commit "$subject"
fi
done
And then run it, passing the SHA-1 hash of the missing blob as the argument:
./find.sh f7880aa1d1a76bfff73f3d602e15b4bc829d6a07
629afc4 ESLint warning in layers' configuration file is fixed.
629afc4
is part of the commit's SHA-1 (it was a last commit I tried to push to remote repository).
Find a file associated with this blob:
git ls-tree -r 629afc4 | grep f7880aa1d1a76bfff73f3d602e15b4bc829d6a07
100644 blob f7880aa1d1a76bfff73f3d602e15b4bc829d6a07 src/config/layers.js
It's src/config/layers.js
in my case.
Check whether hash of the file matches the hash in Git tree:
git hash-object src/config/layers.js
f7880aa1d1a76bfff73f3d602e15b4bc829d6a07
If so then we can write file contents to the blob:
git hash-object -w src/config/layers.js
Doing these steps helped me to remove the error and fix a broken local repository. The solution is found in this article.
The accepted answer or any of the variant did not work for me as git fsck
did not show the missing blob neither did
$ git ls-tree -r HEAD | grep <missing blob hash id>
return anything.
What worked for me was a little hack I employed. I am sharing it in case someone comes across it.
I cloned the repo in a new location and checked it out to the branch I was working on. I shelved the changes in the current corrupted repo (as I had a few changes I could not afford to lose) and then copied over the .git
folder from the newly cloned repo to the old repo. Then I ran git pull
which then worked.
The accepted answer helped me to fix the problem.
However, I suggest a faster fix if missing blobs are files that are in current directory (that was my case).
This means that, for a reason, a file has not been correctly indexed by git, and is causing the missing blob
.
To find a missing blob of 04da887681cecfd6cd59a928008b0e52ffe2a2bf
, you can go to the .git
directory, and launch :
find . -type f -print -exec git hash-object {} \; | grep -B1 04da887681cecfd6cd59a928008b0e52ffe2a2bf
This will go through your data to find the file that is not indexed. If it find something, you now have the file to index:
./myfile.php
04da887681cecfd6cd59a928008b0e52ffe2a2bf
Then, you can index it with: git hash-object -w ./myfile.php
If it doesn't find the file, this means that it was perhaps a previous version of the file, or a file that has been lost.
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