Git History Graph Explorer

The real shape of your history, merges and all.

  • Real parent links
  • Every merge base
  • Reads a .git folder
A small model railway on a wooden desk: three wagons stand on grey tracks that split and rejoin near a little signal box on a patch of grass.

The guide

A git history is a web of parent links, and the merge base you need may not be unique

Every commit records its parents, so a history is a directed acyclic graph; read the links and you can see its real shape and every best common ancestor.

  • 40 or 64 hex digits the length of a SHA-1 or a SHA-256 object name
  • two merge bases main and topic in the worked example, after a criss-cross
  • 12 ahead, 3 behind main against topic in the same example
  • types 6 and 7 offset and reference deltas inside a pack file
Read the full guide Fold the guide 7 min · 19 sources

Most people meet a git history as a list. The terminal prints one commit after another, newest first, and the eye reads it the way it reads a diary. That habit is comfortable and it is wrong. A commit does not know what came before it in a list; it knows only its parents.

That one fact changes everything about how a history should be read. A commit object holds the name of a tree, a timestamp, a log message and the names of zero or more parent commits. A commit with no parent is a root. A commit with two or more is a merge. Nothing else connects one commit to another, so the true shape of a project lives entirely in those parent lines.

A history is a graph, not a line

Follow the parent links from every branch and you get a directed acyclic graph: each commit is a point, each parent link is an arrow pointing back in time, and no chain of arrows ever returns to where it started. The description of version histories as directed acyclic graphs is standard; they are not trees, because merges join lines that had separated.

Git’s own names for the points are long. A SHA-1 repository names every object with 40 hexadecimal digits, and a repository made with the newer SHA-256 format uses 64. So a full name is always 40 or 64 hex digits, and a shorter string such as a1b2c3d is an abbreviation that only means something while it is unique in that repository.

A list cannot show any of this. When a branch is merged, the list puts the merged commits somewhere in date order, between unrelated work, and the reader has to guess which commit came from which line. A graph view puts every commit on a lane and draws each parent link, so the fork and the join are both visible at once.

Why a pasted log needs its parents

The plain git log output is made for people. It prints a Merge: line only on merge commits, and even there the parents are abbreviated. An ordinary commit says nothing about its parent at all. If the log is complete and strictly linear, the next entry is the parent, but the moment two lines of work interleave by date that guess breaks, and a tool that draws from it is drawing fiction.

The cure is to ask git for the links. The pretty-format placeholders include %H for the full hash and %P for the parent hashes, and %x1e and %x1f emit the record and unit separator bytes, which never occur in names or subjects. The one-line and graph outputs carry parents too when --parents is added. A log with parents can be rebuilt exactly; a log without them can only be listed.

Even a complete parent list has edges. A log produced with a limit, a path filter or from a shallow clone mentions parents that are not in it. Those are not errors to hide. They are the boundary of what you pasted, and a careful reader lists them, because any answer that reaches them may be incomplete.

Laying out lanes is a choice

Once the graph exists, it has to be drawn, and here honesty matters. The order of rows must respect the arrows: every child above its parents. Any ordering with that property is a topological sort, every directed acyclic graph has at least one, and Kahn’s algorithm finds one by repeatedly taking a commit whose children are all placed. Among the many valid orders, a good viewer keeps the order you gave it wherever it can.

Columns are harder. Layered graph drawing, the general family this belongs to, places vertices in rows with edges running downward, and its textbook steps rely on heuristics because minimising edge crossings is NP-hard. Git viewers use a simpler lane rule. In the one used here, a commit’s first parent continues its lane, other parents join a lane already waiting for them or open a new one, and a lane is freed when it ends.

The point is not that this rule is best. The point is that it is a drawing decision. Two viewers can lay out the same history with lanes in different places, and both can be faithful. What must never change between them is the graph itself: the same commits, the same parent links, the same answers to every question about reachability.

Merge bases, and why there can be two

The question people most often need answered is where two lines of work last agreed. Git calls the answer a merge base, and its manual defines it carefully. One common ancestor is better than another when the other is its ancestor; a common ancestor with no better one is a best common ancestor, a merge base. In a tree there is exactly one. In a directed acyclic graph there can be several.

The classic case is the criss-cross merge. Two branches each merge the other at about the same time, so each side now contains the other’s latest commit. Neither of those two commits is an ancestor of the other, so neither is better, and both are best. The merge literature names this case because a unique last common ancestor simply does not exist there. Git’s merge-base command with its --all option prints every one of them.

There is a short way to see which common ancestors win. The common ancestors of two commits form a set closed under taking parents. A common ancestor is beaten exactly when one of its own children is also common, so the merge bases are the common ancestors with no common child. That test needs one walk from each side and one pass over the result, which stays linear in the size of the history.

Here is a worked example you can reproduce on the page by loading its example. The history has 24 commits, five of them merges. Branch main merged topic while topic merged main, then each side went on. Ask for the merge bases of main and topic and you get two merge bases: b126b86, “Speed up the walk”, and 61ea0af, “Topic: name the queries”. Git agreed when the same commits were written into a real repository.

The same pair also shows what ahead and behind mean. The three-dot notation in gitrevisions, written main…topic, is the set of commits reachable from either side but not from both. Counting each side gives 12 ahead, 3 behind: twelve commits only main reaches and three only topic reaches. The two-dot form, main..topic, keeps just the right side, the three commits topic would bring in.

A first-parent walk tells a third story. Following only first parents from main gives the line of commits that were made on main or merged into it, twelve here, skipping the inner history of every merged branch. Git’s rev-list command offers this as its first-parent option, and for a well-kept branch it reads like a changelog of merges.

Reading the repository itself

Sometimes there is no log to paste, only a repository folder. Inside it, HEAD names the current branch, refs under refs/heads, refs/tags and refs/remotes name commits, and a packed-refs file records the same information for many refs at once, more compactly. A shallow file lists commits whose parents were cut off by a shallow clone.

Objects live in two forms. A new object sits in its own loose file, compressed with zlib, which wraps Deflate data in a two-byte header and an Adler-32 checksum. Browsers can inflate exactly that format with a DecompressionStream created for the “deflate” format, so a page can read loose objects without any server.

Older objects are gathered into pack files, found through an index that maps each name to an offset. Inside a pack, an object can be stored whole or as a delta against another object, which is how git saves most of its space. Pack entries of types 6 and 7 are those deltas: an offset delta points back a number of bytes in the same pack, and a reference delta names its base outright.

A delta is a list of instructions, copy a range from the base or insert new bytes, and every number in it comes from the file. That makes a pack hostile input in principle. A careful reader checks that each copy stays inside its base, that the result has exactly the declared size, that a chain never loops back on itself, and that inflating stops the moment the output passes the size the header promised.

What this cannot tell you

A graph of parent links says what was merged into what, never why. It cannot tell which commit introduced a bug, whether a rebase rewrote history before it was published, or what the reflog remembers about where a branch used to point. Those live elsewhere or nowhere.

It also cannot see past its input. A log that stops early, a shallow clone, a partial clone that never fetched some objects, or objects borrowed from another store all leave holes, and every answer near a hole is provisional. The honest response is to list the boundary, mark the questions that touch it, and read a longer history when the answer matters.

Sources

Every source consulted for this guide. Links checked October 30, 2026.

  1. Git - git-log Documentation The Git project (git-scm.com)
  2. Git - pretty-formats Documentation The Git project (git-scm.com)
  3. Git - gitrevisions Documentation The Git project (git-scm.com)
  4. Git - git-merge-base Documentation The Git project (git-scm.com)
  5. Git - git-rev-list Documentation The Git project (git-scm.com)
  6. Git - gitrepository-layout Documentation The Git project (git-scm.com)
  7. Git - gitformat-pack Documentation The Git project (git-scm.com)
  8. Git - git-pack-refs Documentation The Git project (git-scm.com)
  9. Git - hash-function-transition Documentation The Git project (git-scm.com)
  10. RFC 1950: ZLIB Compressed Data Format Specification version 3.3 RFC Editor (IETF)
  11. RFC 1951: DEFLATE Compressed Data Format Specification version 1.3 RFC Editor (IETF)
  12. Git - Wikipedia Wikipedia
  13. Directed acyclic graph Wikipedia
  14. Topological sorting Wikipedia
  15. Lowest common ancestor Wikipedia
  16. Layered graph drawing Wikipedia
  17. Merge (version control) Wikipedia
  18. Delta encoding Wikipedia
  19. DecompressionStream: DecompressionStream() constructor MDN Web Docs (Mozilla)