What is the complete list of location where git objects are stored on disk?

82 views Asked by At

I have a git repo and I am trying to find where on disk a particular commit is stored.

  1. git show <HASH> shows the commit.
  2. git cat-file -p <HASH> shows the commit in raw form.
  3. The commit is not under .git/objects/.
  4. The commit is not under .git/lfs/objects/
  5. It is not named inside .git/packed-refs
  6. grep -r <HASH> and find -name '*<PART_HASH>*' does not have any results.

Questions:

  • What location am I missing?
  • Is there a command to find the location?
1

There are 1 answers

0
bk2204 On BEST ANSWER

Git stores objects either as loose objects under a subdirectory of .git/objects or as a packed object in one of the packs in .git/objects/pack. Packing objects stores them more efficiently because they can be stored as a delta (difference) against other objects.

If you want to find the pack in which an object is contained, you can list the corresponding index by piping one of the .idx files under .git/objects/pack to git show-index. That will list the objects contained in the corresponding pack.

For example, in my local copy of git/git:

$ git show-index < .git/objects/pack/pack-0ebde31e89dd275864d40ae21ad3228a9dc7d0ea.idx | \
  head -n5
116264 0049c569260e2acbe490aabd267b233e9db28e8d (f0b1bf76)
182726 005e07db39e571eb3e73fbf7e4dbe5c67ad73e1e (29e2a47f)
99906 00c6aa0351c8d3abbcbee96d50cd7a359dd68a33 (e7952421)
477311 01724db3b51dc57d9e53e753148b5fbf548aa094 (0f597941)
186631 01b76e6be63bd19e446b3ede742bff887b7e81d5 (fd3f4a72)

The center portion is the object ID, which is probably what you're looking for.

Note that packed-refs contains only packed refs; if the object is not the head of any ref, then it won't appear there (or in any loose ref file). Also note that core Git does not store anything under .git/lfs/objects, and the objects stored there by Git LFS are entirely separate and independent objects from Git objects, even if the repository is using SHA-256 for objects.