Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding the git data model

Tags:

git

I have recently started reading Git Internals to understand how git works under the hood. There is a diagram in this book showing the Git data model :

enter image description here

In this figure I cannot understand what is the meaning of those circles around commit and tree objects. Also the meaning of those three lines from tree to blob is not clear to me. I am wondering if anyone could explain to me what those elements mean in git data model.

like image 707
amiref Avatar asked Dec 06 '25 18:12

amiref


1 Answers

TL;DR: Those circles are actually arrows like the rest of the lines, meaning that commits can reference other commits and trees can reference other trees.


All of the lines in this diagram denotes references, A can reference B.

So:

  • HEAD can reference a branch (truthfully, HEAD can also reference directly a commit and bypass the branch but let's not overcomplicate your situation just yet)
  • a branch can reference a specific commit
  • a tag can also reference a specific commit
  • a commit can reference a tree (the "directory" of the repository snapshot)
  • a tree can reference one or more blobs, files in that directory

However, the circles you ask about mean this:

  • A commit usually refers to its parent commits
    • The very first commit in your repository has no parents, and thus reference 0 other commits
    • Normal commits that arent merges reference their immediate parent, and thus reference 1 other commit
    • Merge commits reference the two parents that were merged (or more than two if you do an octopus merge, again, don't overcomplicate so ignore this part)
  • A tree is like a directory of a single folder and can thus reference
    • The blobs (files) in that single folder
    • Trees that make up subfolders

So that's that those circles mean, commits and trees can reference recursively commits and trees. There might be an arrowhead missing that made it harder to understand, but that's what those circles mean, they're just round arrows really.

like image 127
Lasse V. Karlsen Avatar answered Dec 08 '25 08:12

Lasse V. Karlsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!