Search code examples
gitgithubgit-clone

object directory has no objects after a git clone


After I do a git clone of a remote repository, why is the .git/objects directory not have any of the objects and their parent directories that start with the first two characters of the sha1 hash (it has the info and pack directories though). I only start seeing the objects after I make my own commits. And how is git log able to work in this case without any of the commit objects ?


Solution

  • Git can store objects either as loose objects, in which case they end up in one of these directories named after the first byte, or as a pack, which stores the objects in a special compressed format. When there are too many loose objects, git gc will run to pack them automatically.

    When you do a clone, the server provides you all of the objects you need in a pack, so it doesn't make sense to explode this pack into loose objects (unless there are a very small number), so Git doesn't, and simply leaves the objects in the pack.

    As you create new objects, they're typically written as loose objects, since there is some overhead in creating an efficient pack, and only turned into a pack as part of git gc.