Cjku/git/backgound knowledge

From MozillaWiki
Jump to: navigation, search

Commit graphs

Directed acyclic graph


Git chooses directed acyclic graph (DAG) as commit tree pattern. Regards to DAG, you may refer to Wikipedia::DAG. Here is brief version:

  1. Directed - all edges are one-direction.
  2. Acyclic - That means departure from a vertex, with no repetitions of vertices and edges allowed, there is no path lead back to the origin.

Git commit graph is DAG, and this graph consists of commit object, tee object and blob object. Symbolic refs, such as HEAD/ORIG_HEAD, or refs, branch and tag, are not part of a commit graphs. They just refer to commit graph. Generally speaking, a symbolic ref refers to a ref; a ref refers to a commit object.

This design logic appears in git all around.

  1. If you know a SHA1 of a commit object, you can trace back all its ancestor, while you have no idea how many descendants it has. And that's the reason why we use HEAD(tip of a path) that often.
  2. local repository, which is cloned from a remote, knows the URL of a depot; while that depo has no idea how many clone repos scatter on the internet.