HeadlinesBriefing favicon HeadlinesBriefing.com

Inside .git: How Git Stores Commits

DEV Community •
×

Running git init creates a hidden .git directory that functions as a lightweight database for every change. Instead of storing whole file snapshots like legacy VCS, Git writes each piece of data as an object identified by a SHA‑1 hash. This design shrinks repository size and speeds up operations.

Inside .git/objects you’ll see directories named with the first two characters of each hash, such as 48/, and files named with the remaining 38 characters. A commit object stores author, timestamp, and a pointer to a tree; the tree maps the directory layout, while blob objects hold the actual file contents.

When you run git log, Git prints the hash and metadata, and git cat-file can reveal the object type and its links. A git checkout of a hash forces Git to read the commit, follow its tree to the blobs, and reconstruct the working directory. Understanding this flow helps when debugging history or building visualization tools.