A Git Commit as a Snapshot with Parents

A commit identifies project contents, ancestry, and metadata. The difference a reader sees is obtained by comparing that snapshot with another one.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Compare two related snapshots
  2. Follow more than one parent
  3. Follow a parent relationship through a concrete change
  4. Account for metadata and parents when comparing identities

Compare two related snapshots

A commit adding a paragraph has a tree containing the entire recorded file. The display of one added paragraph arises from comparing it with its parent tree. Reading a diff explains that comparison.

Follow more than one parent

A merge commit can connect two earlier lines of development. The visual change differs depending on which parent the viewer compares. See merge commits for how those parent links identify the history.[1]

Follow a parent relationship through a concrete change

A commit can contain two files with contents X and Y. Its child can reuse the representation of the unchanged second file while replacing X with X′. Each commit still identifies a full tree for the project. A diff compares snapshots to show a change. See branch references.

Commit A: {first:X, second:Y}
Commit B with parent A: {first:X′, second:Y}
Relative diff A→B: change first only

Account for metadata and parents when comparing identities

Separate commits may have the same file contents while different parents or metadata give them distinct identities. A merge can record more than one parent. Discuss what changed in content independently from where the commit sits in history.

References

  1. Scott Chacon and Ben Straub, Pro Git ↩