Understanding Git as a graph of immutable objects

Summary

Charles Duan explains blobs, trees, commits and references as the connected data model behind Git's everyday commands. Git uses four central object types.

Ideas

  • Blobs store file contents without path names.
  • Trees link names with blobs and further trees.
  • Commits point to a tree and previous commits.
  • References give immutable commit objects movable names.
  • The index prepares the tree of the next commit.
  • Merge commits connect several parents in a shared graph.

Insights

  • Commands become predictable once their changes to objects are visible.
  • Content addressing automatically makes identical data shareable.
  • History is a graph and not necessarily a linear timeline.
  • Movable references provide convenience on top of immutable states.

Facts

  • Object names are derived from cryptographic hash values.
  • A commit does not contain a complete branch name.
  • Tags can provide fixed names for particular objects.

Recommendations

  • Examine a test repository with git cat-file and git ls-tree.
  • Check references and the reflog before risky operations.
  • Think in common ancestors and graph edges when merge problems arise.

References

Read the original article

Search the Web Archive

Found a mistake or have something to add? Get in touch.