how/objects
Inside, Git is four object types and one big hash table. Let's see how a file on disk turns into a commit with a SHA, and why the whole history is cryptographically linked.
If you strip every command out of Git and keep a single idea, what
remains is this: the object database. The .git/objects/ folder,
where Git stores four object types:
(permissions, type, SHA, name).tree plus metadata (author, time, parents,
message).Each object is addressed by its [[sha1|SHA]], a hash of its own content. Identical files get the same SHA and are stored once. History is a chain of commits where each one references its parent.
Press ▶ to follow how three files turn into one commit in four steps.
A project folder with three files in it: README.md,
index.html, style.css. From Git's point of view this is the working copy
(working-tree), just the content of the file system that you
edit code in.
Git has not seen them yet. There is nothing of ours in .git/objects/, and the
index is empty. To commit anything, the files first have to be
turned into objects.
recap
What to remember:
.git/refs/heads/main is
an ordinary text file; it holds the 40-character SHA of a commit. Moving
a branch means rewriting this file.The plumbing commands (hash-object, write-tree, commit-tree,
cat-file) do exactly these steps, one at a time. The high-level
git commit glues them into a single operation.