Overview
Git’s object model is the foundation of its version control system. At its core, Git is a content-addressable filesystem with a VCS user interface written on top of it. This means that Git stores everything as objects identified by SHA-1 (or SHA-256) hashes of their contents.The Four Object Types
Git has four fundamental object types that represent all data in the repository:Blob
Stores file data - the content of your files without any metadata.
Tree
Represents directories, containing references to blobs and other trees.
Commit
Captures a snapshot of the project at a point in time with metadata.
Tag
Creates a named reference to a specific commit, often with a message.
Object Storage
Content-Addressable Storage
Each object is stored with its SHA-1 hash as the identifier:The first two characters of the hash form the directory name, and the remaining 38 characters form the filename in
.git/objects/.Object Storage Format
Blob Objects
Blobs store file content without any metadata:Tree Objects
Trees represent directory structures:File Modes
| Mode | Description |
|---|---|
100644 | Regular file (non-executable) |
100755 | Executable file |
120000 | Symbolic link |
040000 | Subdirectory (tree) |
160000 | Gitlink (submodule) |
Commit Objects
Commits are snapshots with metadata:Commit Structure
- tree: Points to the root tree object
- parent: References parent commit(s) (merge commits have multiple parents)
- author: Who wrote the changes
- committer: Who committed the changes
- message: Commit message
Tag Objects
Annotated tags create permanent named references:Object Relationships
Git objects form a directed acyclic graph (DAG):Object Inspection Commands
git cat-file
git cat-file
Examine object contents and metadata:
git hash-object
git hash-object
Create objects from files:
git ls-tree
git ls-tree
List contents of tree objects:
Object Packing
Git optimizes storage by packing objects:Packed objects use delta compression to store only differences between similar objects, dramatically reducing repository size.
Related Topics
- Pack Format - How Git efficiently stores objects
- Index Format - The staging area structure
- Commit Graph - Optimizing commit history access
