lab 22 Git Internals:
The .git directory
- Learn about the structure of the
Time to do some exploring. First, from the root of your project directory…
ls -C .git
$ ls -C .git COMMIT_EDITMSG config index objects HEAD description info refs ORIG_HEAD hooks logs
This is the magic directory where all the git “stuff” is stored. Let’s peek in the objects directory.
The Object Store
ls -C .git/objects
$ ls -C .git/objects 09 24 33 43 6b 96 9c b5 e4 pack 11 27 35 59 78 97 a3 c4 e7 12 28 3c 69 8b 98 af df info
You should see a bunch of directories with 2 letter names. The directory names are the first two letters of the sha1 hash of the object stored in git.
Deeper into the Object Store
ls -C .git/objects/<dir>
$ ls -C .git/objects/09 6b74c56bfc6b40e754fc0725b8c70b2038b91e 9fb6f9d3a104feb32fcac22354c4d0e8a182c1
Look in one of the two-letter directories. You should see some files with 38-character names. These are the files that contain the objects stored in git. These files are compressed and encoded, so looking at their contents directly won’t be very helpful, but we will take a closer look in a bit.
$ cat .git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = true [user] name = Jim Weirich email = jim (at) edgecase.com
This is a project-specific configuration file. Config entries in here will override the config entries in the
.gitconfig file in your home directory, at least for this project.
Branches and Tags
ls .git/refs ls .git/refs/heads ls .git/refs/tags cat .git/refs/tags/v1
$ ls .git/refs heads tags $ ls .git/refs/heads master $ ls .git/refs/tags v1 v1-beta $ cat .git/refs/tags/v1 9811d9e446d4790217484450b0dd756915174341
You should recognize the files in the tags subdirectory. Each file corresponds to a tag you created with the
git tag command earlier. Its content is just the hash of the commit tied to the tag.
The heads directory is similar, but is used for branches rather than tags. We only have one branch at the moment, so all you will see is master in this directory.
The HEAD File
$ cat .git/HEAD ref: refs/heads/master
The HEAD file contains a reference to the current branch. It should be a reference to master at this point.