git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v5] doc: add an explanation of Git's data model

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 31, 2025, 14:44 UTC
Message-ID
<xmqqtszf2kro.fsf@gitster.g>
In-Reply-To
<pull.1981.v5.git.1761856336360.gitgitgadget@gmail.com>
"Julia Evans via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 66 quoted lines
> diff --git a/Documentation/gitdatamodel.adoc b/Documentation/gitdatamodel.adoc
> new file mode 100644
> index 0000000000..1cefbb4833
> --- /dev/null
> +++ b/Documentation/gitdatamodel.adoc
> @@ -0,0 +1,296 @@
> +gitdatamodel(7)
> +===============
> +
> +NAME
> +----
> +gitdatamodel - Git's core data model
> +
> +SYNOPSIS
> +--------
> +gitdatamodel
> +
> +DESCRIPTION
> +-----------
> +
> +It's not necessary to understand Git's data model to use Git, but it's
> +very helpful when reading Git's documentation so that you know what it
> +means when the documentation says "object", "reference" or "index".
> +
> +Git's core operations use 4 kinds of data:
> +
> +1. <<objects,Objects>>: commits, trees, blobs, and tag objects
> +2. <<references,References>>: branches, tags,
> +   remote-tracking branches, etc
> +3. <<index,The index>>, also known as the staging area
> +4. <<reflogs,Reflogs>>: logs of changes to references ("ref log")
> +
> +[[objects]]
> +OBJECTS
> +-------
> +
> +All of the commits and files in a Git repository are stored as "Git objects".
> +Git objects never change after they're created, and every object has an ID,
> +like `1b61de420a21a2f1aaef93e38ecd0e45e8bc9f0a`.
> +
> +This means that if you have an object's ID, you can always recover its
> +exact contents as long as the object hasn't been deleted.
> +
> +Every object has:
> +
> +[[object-id]]
> +1. an *ID* (aka "object name"), which is a cryptographic hash of its
> +  type and contents.
> +  It's fast to look up a Git object using its ID.
> +  This is usually represented in hexadecimal, like
> +  `1b61de420a21a2f1aaef93e38ecd0e45e8bc9f0a`.
> +2. a *type*. There are 4 types of objects:
> +   <<commit,commits>>, <<tree,trees>>, <<blob,blobs>>,
> +   and <<tag-object,tag objects>>.
> +3. *contents*. The structure of the contents depends on the type.
> +
> +Here's how each type of object is structured:
> +
> +[[commit]]
> +commit::
> +    A commit contains these required fields
> +    (though there are other optional fields):
> ++
> +1. The full directory structure of all the files in that version of the
> +   repository and each file's contents, stored as the *<<tree,tree>>* ID
> +   of the commit's base directory.

"base directory" is a new term; I think we most often use "top-level" directory (in various spellings).

$ git grep -e 'base directory' -e 'level directory' Documentation/
Show 8 quoted lines
> +[[tree]]
> +tree::
> +    A tree is how Git represents a directory.
> +    It can contain files or other trees (which are subdirectories).
> +    It lists, for each item in the tree:
> ++
> +1. The *filename*, for example `hello.py`
> +2. The *file mode*. Git has these file modes. which are only

"has these" -> "uses only these" to clarify that this is an exhaustive enumeration and users cannot invent 100664 and others, which is a mistake Git itself used to make/allow.

Show 7 quoted lines
> +[[tag-object]]
> +tag object::
> +    Tag objects contain these required fields
> +    (though there are other optional fields):
> ++
> +1. The object *ID* it references
> +2. The object *type*
I would rephrase these to
    1. The *ID* of the object it references
    2. The *type* of the object it references

because (1) a tag object references another object, not ID. To name the object it reference, it uses the object name of it, but just like your name is not you, object name is not the object (it merely is *one* way to refer to it). (2) unless it is very clear to readers that "The object" in 1. and 2. refer to the same object, 2. invites a question "type of which object?".

> +[[branch]]
> +branches: `refs/heads/<name>`::
> +    A branch refers to a commit ID.
A branch refers to a commit object (by its ID).  Ditto for tags.
Show 7 quoted lines
> +NOTE: Git may delete objects that aren't "reachable" from any reference.
> +An object is "reachable" if we can find it by following tags to whatever
> +they tag, commits to their parents or trees, and trees to the trees or
> +blobs that they contain.
> +For example, if you amend a commit, with `git commit --amend`,
> +the old commit will usually not be reachable, so it may be deleted eventually.
> +Reachable objects will never be deleted.

Very good write-up. As we would touch upon reflog later in the same document, we may want to extend the "amend" example a bit, perhaps like

    Note: Git never deletes objects that are "reachable".  An object
    is "reachable" if ....  An unreachable object may be deleted.
    For example, ... a newly created commit will replace the old
    commit and the current branch ref points at the new commit.  The
    old commit is recorded in the <<reflogs,reflog>> of the current
    branch, so it is still "reachable", but sufficiently old reflog
    entries are expired away, the old commit may become unreachable
    at that point, and would get deleted.
Other than the above, I found everything very nicely written.
Thanks.
Previous: Julia Evans via GitGitGadgetNext: Patrick Steinhardt
Message 48 of 89 in “doc: add a explanation of Git's data model”
  1. doc: add a explanation of Git's data modelJulia Evans via GitGitGadget, Oct 3, 2025
  2. Kristoffer HaugsbakkOct 3, 2025
  3. Julia EvansOct 6, 2025
  4. D. Ben KnobleOct 6, 2025
  5. Julia EvansOct 6, 2025
  6. D. Ben KnobleOct 6, 2025
  7. Julia EvansOct 9, 2025
  8. Kristoffer HaugsbakkOct 8, 2025
  9. Junio C HamanoOct 6, 2025
  10. Julia EvansOct 6, 2025
  11. Kristoffer HaugsbakkOct 7, 2025
  12. Junio C HamanoOct 7, 2025
  13. Patrick SteinhardtOct 7, 2025
  14. Junio C HamanoOct 7, 2025
  15. Julia EvansOct 7, 2025
  16. Junio C HamanoOct 7, 2025
  17. D. Ben KnobleOct 7, 2025
  18. Julia EvansOct 7, 2025
  19. Patrick SteinhardtOct 8, 2025
  20. Junio C HamanoOct 8, 2025
  21. Julia EvansOct 8, 2025
  22. doc: add a explanation of Git's data modelJulia Evans via GitGitGadget, Oct 8, 2025
  23. Patrick SteinhardtOct 10, 2025
  24. Junio C HamanoOct 13, 2025
  25. Patrick SteinhardtOct 14, 2025
  26. Julia EvansOct 14, 2025
  27. Patrick SteinhardtOct 14, 2025
  28. Junio C HamanoOct 14, 2025
  29. doc: add a explanation of Git's data modelJulia Evans via GitGitGadget, Oct 14, 2025
  30. Patrick SteinhardtOct 15, 2025
  31. Junio C HamanoOct 15, 2025
  32. Julia EvansOct 15, 2025
  33. Junio C HamanoOct 15, 2025
  34. Julia EvansOct 16, 2025
  35. Junio C HamanoOct 15, 2025
  36. Julia EvansOct 16, 2025
  37. Junio C HamanoOct 16, 2025
  38. Julia EvansOct 16, 2025
  39. Junio C HamanoOct 16, 2025
  40. Kristoffer HaugsbakkOct 16, 2025
  41. Kristoffer HaugsbakkOct 20, 2025
  42. Junio C HamanoOct 20, 2025
  43. doc: add an explanation of Git's data modelJulia Evans via GitGitGadget, Oct 27, 2025
  44. Junio C HamanoOct 27, 2025
  45. Julia EvansOct 28, 2025
  46. Junio C HamanoOct 28, 2025
  47. doc: add an explanation of Git's data modelJulia Evans via GitGitGadget, Oct 30, 2025
  48. Junio C HamanoOct 31, 2025
  49. Patrick SteinhardtNov 3, 2025
  50. Junio C HamanoNov 3, 2025
  51. Julia EvansNov 3, 2025
  52. Junio C HamanoNov 4, 2025
  53. Julia EvansNov 4, 2025
  54. Junio C HamanoNov 4, 2025
  55. Julia EvansNov 4, 2025
  56. Junio C HamanoNov 4, 2025
  57. Julia EvansNov 5, 2025
  58. Ben KnobleNov 5, 2025
  59. Julia EvansNov 5, 2025
  60. Ben KnobleNov 6, 2025
  61. Junio C HamanoOct 31, 2025
  62. Patrick SteinhardtNov 3, 2025
  63. Julia EvansNov 3, 2025
  64. doc: add an explanation of Git's data modelJulia Evans via GitGitGadget, Nov 7, 2025
  65. Junio C HamanoNov 7, 2025
  66. Junio C HamanoNov 7, 2025
  67. Julia EvansNov 7, 2025
  68. Junio C HamanoNov 7, 2025
  69. Junio C HamanoNov 8, 2025
  70. Ben KnobleNov 9, 2025
  71. Junio C HamanoNov 9, 2025
  72. Julia EvansNov 10, 2025
  73. Junio C HamanoNov 11, 2025
  74. Ben KnobleNov 11, 2025
  75. Julia EvansNov 11, 2025
  76. Junio C HamanoNov 12, 2025
  77. Junio C HamanoNov 12, 2025
  78. Julia EvansNov 13, 2025
  79. Junio C HamanoNov 13, 2025
  80. Julia EvansNov 13, 2025
  81. Chris TorekNov 13, 2025
  82. Junio C HamanoNov 13, 2025
  83. doc: add an explanation of Git's data modelJulia Evans via GitGitGadget, Nov 12, 2025
  84. Junio C HamanoNov 12, 2025
  85. Junio C HamanoNov 23, 2025
  86. Patrick SteinhardtDec 1, 2025
  87. Junio C HamanoDec 2, 2025
  88. Julia EvansOct 9, 2025
  89. Ben KnobleOct 10, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.