generation_numbers 

Send to Kindle
home » snippets » git » generation_numbers



Snippets

From:  http://www.spinics.net/lists/git/msg161165.html

A commit's generation is its height in the history graph, as measured from the farthest root.  It is defined as:

The following diagram shows a sample history with generations:

  A(0)--B(1)--C(2)------G(5)--H(6)
         \             /
          D(2)--E(3)--F(4)

Note that C and D have the same generation, as they are both children of B.  Note also that the merge commit G's generation is 5, not 3, as we take the maximum of its parents' generations.

Generation numbers can be useful for bounding traversals.  For example, if we have two commits with generations 500 and 600, we know that the second cannot be an ancestor of the first.  The first could be an ancestor of the second, but we can't know unless we traverse the history graph.  However, when walking backwards from the "600" commit, once we reach generation "499", we know that the "500" commit cannot be an ancestor of the "499" commit, and we can stop the traversal without even looking at the earlier parts of the history.