Missing hashes in .git object folder

Viewed 562

I was going through the internal of how git works. I was reading that git stores everything in objects folder. It first make SHA1 hash of file and stores it in Object folder. I tried the following commands on 1 of my repository, but i couldn't find the hash file in the objects directory but using cat-file command, i am able to see the command. Is there something i am missing. Below are the steps are i did to understand.

I did git log to find the latest commit,

enter image description here

then i cat-file the mentioned commit id and can see the hash of tree file.

enter image description here

If i go to objects folder and search for the folder with 1st two characters of the hash, i am not able to find the folder.

enter image description here

But still i am able to get the file.

enter image description here

I tried it for files (blob) also from the cat-file of tree, but couldn't find the files with hash in objects folder. Can anyone help me understand why?

1 Answers

You should take a look at :

.git/objects/pack

… too.

Git indeed use the object system you describe but eventually, when there's too many of them, Git will put the garbage collector in charge of packing them, that is gathering some of them then concatenating them into a single file (without compressing, though, since objects are already compressed. They're therefore directly accessible in the middle of pack file). Aside of this, an index file "*.idx" is created too in order to quickly retrieve them.

This both scavenges useful inodes and space remaining at the end of each file's last block on the filesystem, but the operation takes time and ressources. That's why Git will trigger this operation only at certain times.

See: Git Internals: Pack Files.

Related