Key Takeaways
- Git is a Content-Addressable Filesystem: It stores data based on the hash of its content, not its filename.
- The
.gitdirectory: Contains everything needed to reconstruct the project history (objects,refs,HEAD,config). - Four Object Types:
- Blob: File content (no metadata).
- Tree: Directory structure (filenames, permissions).
- Commit: Snapshot history (author, parent, message).
- Tag: Reference to a commit (lightweight or annotated).
- Plumbing vs Porcelain: Porcelain commands (
commit,add) are for humans; Plumbing commands (write-tree,update-ref) are for scripts and internal operations. - SHA-1: The cryptographic hash function used to identify every object.
- Packfiles: Git saves space by compressing objects and storing only the differences (deltas) in packfiles.
Interactive Flashcards
What does a Blob object store?
(Click to flip)Only the file content.
It does NOT store the filename, permissions, or timestamp.
What is the difference between Porcelain and Plumbing?
Porcelain: High-level, user-friendly commands (e.g., git add).
Plumbing: Low-level, core commands (e.g., git hash-object).
What does HEAD usually point to?
A reference to the current branch (e.g., refs/heads/main).
In "detached state", it points directly to a commit hash.
Which plumbing command creates a Tree object from the Index?
git write-tree
Why is Git's storage called "Content-Addressable"?
Because data is retrieved using a key derived from its content (the SHA-1 hash), rather than an arbitrary location or ID.
What is a Packfile?
A compressed file containing multiple objects and their deltas (differences), used to save disk space.
Plumbing Cheat Sheet
| Command | Type | Purpose |
|---|---|---|
git hash-object -w <file> |
Plumbing | Compute object ID and optionally create a blob from a file |
git cat-file -p <sha> |
Plumbing | Provide content or type and size information for repository objects |
git update-index --add <file> |
Plumbing | Register file contents in the working tree to the index |
git write-tree |
Plumbing | Create a tree object from the current index |
git commit-tree <tree-sha> |
Plumbing | Create a new commit object |
git update-ref <ref> <sha> |
Plumbing | Update the object name stored in a ref safely |
git symbolic-ref HEAD |
Plumbing | Read or modify the HEAD reference |
git rev-parse <ref> |
Plumbing | Pick out and massage parameters (convert branch name to SHA) |
git fsck |
Plumbing | Verifies the connectivity and validity of the objects in the database |
git gc |
Plumbing | Cleanup unnecessary files and optimize the local repository (create packfiles) |
Filesystem Cheat Sheet
| File/Dir | Purpose |
|---|---|
.git/HEAD |
Pointer to current branch |
.git/config |
Local repository configuration |
.git/index |
Binary staging area (file stats + SHA1s) |
.git/objects/ |
Database of all content |
.git/objects/pack/ |
Directory for packfiles (compressed objects) |
.git/refs/heads/ |
Pointers to local branch tips |
.git/refs/tags/ |
Pointers to tags |
.git/hooks/ |
Scripts triggered by Git actions |
Next Steps
You have completed the Git Internals module! You now possess a deep understanding of the engine that powers the world’s most popular version control system.