git commit
The Snapshot
The git commit command is often thought of as the command that "saves your files". But as we learned with git add, your files were already saved as Blobs! So what does git commit actually do? It just runs three simple plumbing commands to wrap everything up.
The 3-Step Process
Click the commit button below to watch the exact sequence of events that occurs when you finalize a commit.
1. Index
2. Objects Database
3. References
Step 1: Write the Tree
Git looks at the Staging Area (.git/index). It takes all the Blobs listed there, bundles them together with their filenames, and hashes them into a single Tree Object. This Tree represents the exact directory structure of your project at this moment.
Step 2: Write the Commit
Git creates a Commit Object. This object is just a small text file containing your name, email, the commit message, the hash of the parent commit, and a pointer to the Tree Object created in Step 1.
Step 3: Update the Reference
Finally, Git looks at where your HEAD is currently pointing (e.g., .git/refs/heads/main) and simply replaces the old commit hash in that text file with the new commit hash it just generated.
Proving the Architecture
We can completely bypass git commit and build a commit ourselves using the exact low-level plumbing commands Git uses under the hood.