Understanding Git History as a DAG
What you'll learn: How Git structures commit history as a directed acyclic graph (DAG), enabling powerful history manipulation and branching workflows.
What is a DAG?
A Directed Acyclic Graph sounds complex, but break it down:
- Graph: A collection of nodes (points) connected by edges (lines)
- Directed: The connections have arrows—they point from one node to another
- Acyclic: You can't follow the arrows in a circle back to where you started
Git Commits as a Graph
Every Git commit is a node in this graph. Each commit points backward to its parent commit(s)—the commit(s) that came before it. Think of it like a family tree where children know their parents, but parents don't track every descendant.
When you viewed history with git log, you saw this chain: each commit references the one before it. A branch is simply a pointer (a label) to one specific commit in this graph.
Why This Matters
This DAG structure explains everything you've learned:
- Branches are just movable pointers to commits in the graph
- Fast-forward merges happen when one branch's commit is a direct ancestor of another—you just move the pointer forward along the same path
- Three-way merges create a new commit with two parents, joining separate paths in the graph
- Merge conflicts occur when different paths modified the same content differently
The "acyclic" part is crucial: commits only point to ancestors, never forward. This prevents loops and makes history predictable and safe to traverse backward.
Key Takeaway: Git history is a directed acyclic graph where commits point to parent(s), branches are pointers to commits, and this structure makes branching cheap and merging powerful—the foundation for all Git operations you've learned.