'git cat-file -p <sha1>': "fatal: Not a valid object name" on random objects from .git/objects
You don't have to cd into the .git object store, but you have to provide enough of the full sha1 hash for git to uniquely identify the object.
Usually the first 6 or 7 digits is sufficient. Git matches the object IDs starting from the front, so entering any substring, such as the last several digits, will fail (or match to a different object than you intended).
git cat-file -p 621087f408e2f2bd782d53a1211a7418fee4f6a7
Git stores its objects in .git/objects
, distributed across 256 folders to keep the size of the directory down. The first two characters of each hash are used as directory name, the remaining 38 chars are used as filename.
Thanks to @knittl for a great answer.
You can get build all of the objects with this bash script.
cd .git/objects;
for d in * ; do (
cd "$d";
for p in * ; do ( echo "$d$p";); done
); done
Or you can get a run cat -p on everything!
cd .git/objects;
for d in * ; do (
cd "$d";
for p in * ; do (
echo "$d$p";
git cat-file -p $d$p
); done
); done