git_objects
git objects
Understanding Git's internal data structures.
π§± Object Types
| Type | Description |
|---|---|
| blob | File contents |
| tree | Directory listing |
| commit | Snapshot + metadata |
| tag | Named reference |
π Object Relationships
graph TD
A[Commit] -->|tree| B[Tree]
B -->|blob| C[file.txt]
B -->|tree| D[src/]
D -->|blob| E[app.js]
A -->|parent| F[Previous Commit]
π Examine Objects
View Object Type
git cat-file -t abc1234
Shows type: blob, tree, commit, or tag.
View Object Content
git cat-file -p abc1234
Displays the content of the object.
View Object Size
git cat-file -s abc1234
Shows size in bytes.
π¦ Blob Objects
Create Blob (Hash a File)
echo "Hello" | git hash-object --stdin
Computes SHA-1 hash of content.
Store Blob
echo "Hello" | git hash-object -w --stdin
Computes hash AND stores blob.
View Blob Content
git cat-file -p abc123
Displays file contents.
π³ Tree Objects
View Tree
git cat-file -p HEAD^{tree}
Shows directory contents of HEAD.
Output:
100644 blob abc123 README.md
040000 tree def456 src
View Subtree
git ls-tree HEAD src/
Lists contents of src/ directory.
π Commit Objects
View Commit
git cat-file -p HEAD
Shows commit details.
Output:
tree abc123...
parent def456...
author Name <email> timestamp
committer Name <email> timestamp
Commit message
Show Commit Tree
git show HEAD --format="%T"
Shows tree hash of commit.
π·οΈ Tag Objects
View Tag
git cat-file -p v1.0.0
Shows tag details (for annotated tags).
π Object Storage
Objects stored in .git/objects/:
.git/objects/
βββ ab/
β βββ cd1234... # First 2 chars = folder
βββ pack/
β βββ pack-*.pack # Compressed objects
π Object Commands
Count Objects
git count-objects -v
Shows object count and size.
Verify Objects
git fsck
Checks object integrity.
Garbage Collect
git gc
Cleans up and optimizes object storage.
π‘ Tips
Explore Any Object
git cat-file -p main:src/app.js
View specific file at specific branch.
Objects are Immutable
Once created, objects never change - new versions get new hashes.
π Related
#git #objects #internals #blob #tree