Understanding Commits

A commit object is very small, but it links together massive amounts of information.

The Anatomy of a Commit

Let’s use git cat-file -p to inspect a raw commit object:

$ git cat-file -p HEAD
tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
parent a8b23c...
author Jane Doe <jane@example.com> 1610000000 +0000
committer Jane Doe <jane@example.com> 1610000000 +0000

Initial commit for the new feature

Linking the Tree

The tree line points to a tree object, which behaves somewhat like a directory listing. The tree object subsequently points to file contents, known as blobs.

The Parents

The parent line connects the commit history. The only commit lacking a parent is the initial commit.

Wrapping Up

With these tiny text snapshots, Git forms a directed acyclic graph (DAG) of the complete history.