History is a chain: each commit (after the first) records its parent, the commit that came before it. Today you add the parent line, turning isolated commits into a linked graph.
Build a commit with a parent line and hash it to its exact id.
A parent line is what makes history a graph rather than a pile of snapshots.
It goes immediately after the tree line and before the author line, and it
holds the id of the preceding commit. A commit can have zero parents (the very
first commit), one parent (the normal case), or several (a merge), and each parent
gets its own line in order. Since the parent id is part of the body, it feeds the
hash, which is what chains the whole history together into a tamper-evident
sequence: change any old commit and every descendant’s id changes.
Here the second commit changes hello.txt to hello world, producing a new blob,
a new root tree 4ab82d44..., and, with the parent pointing back at the first
commit, the id 9bae7f0a.... That is a two-commit history, cryptographically
linked. We will walk exactly this chain when we build log.
// parent lines go after tree, before author, one per parent, in orderbody := "tree " + tree + "\n"for _, p := range parents {body += "parent " + p + "\n"}body += "author " + ident + "\n" // ...committer, blank, message