Wyckham Seelig
Wyckham Seelig

Reputation: 19

Where is git blob containing file

I am trying to figure out where git stores the blob that contains a file. To do this, I first do a git cat-file -p of the last commit to my repo. This tells me where the tree is located, so I do a ls-tree on that hash and see all of the files [and subtrees] in that latest commit. Each line of the output of the ls-tree command shows permissions, type (blob or tree), a hash, and the file (or directory if it is a tree) name.

My problem is that the hashes shown in this listing are not found in my .git/objects directory. I can do a git cat-file -p on the hash in the ls-tree command, and it correctly shows the file, but I cannot find the blob where that file is stored.

I think that what may be happening here is that the hash shown in the ls-tree is a not a hash of the file, bur rather a hash of the file's hash coupled with other information in the tree object [like the file name]. If that is the case, I would like to be able to look "under the skin" of that tree object to find the real hash of the blob that stores the file.

Is this at all possible??

I have already tried the first suggestion below, and the hashes are simply not there. I don't want to try the second one because I'm not sure if it would rewrite material into my repo.

Upvotes: 1

Views: 1090

Answers (1)

torek
torek

Reputation: 488203

The fundamental issue here is that Git makes no promises about where and how the blob object is stored. The .git/objects/ab/cdef... files are the initial location, and is where all current versions of Git store what Git calls loose objects, but loose objects are eventually packed, which compresses them further.

A packed object exists as delta chains within a .pack file. In a normal pack file, all the "parts" that make up the complete object are in the same pack file. A "thin" pack can be delta-compressed against objects that are not present in that same pack file. For some further details, see the technical documentation.

Generally, you don't need to mess with object and pack files at all. Just use git cat-file -p <hash-id> to obtain the data from the given hash ID.

If, for some strange reason, you want a loose object out of a pack file, you can use git unpack-objects to explode a pack file into its individual components. Note that this cannot be used on a pack file that exists in the repository, nor on a thin pack. If you have a stray thin pack, you must fix it up with git index-pack --fix-thin first.

Upvotes: 3

Related Questions