Git & GitHub Course
Git & GitHub
/
Advanced

Blobs, Trees & Commits

Definition

The three fundamental data structures Git uses to store information. Blobs store file data, Trees store directory structures, and Commits store metadata linking to a Tree.

Explain Like I'm New

Think of it like a computer filesystem. - A Blob is a File (e.g., the actual text inside `index.html`). - A Tree is a Folder (It just contains a list of Blobs and other Trees). - A Commit is a sticky note (It says 'John Doe saved this Tree on Tuesday').

Real World Example

When you type `git commit`, Git literally creates a Blob for every file, a Tree for every folder, and wraps a Commit object around the root Tree.

Common Use Cases

  • •Advanced repository recovery

Terminal Output

bash / terminal
/* The structure of a Commit in Git's brain: [COMMIT Object: Hash 9a3b...] │ Author: John Doe │ Message: "Initial Commit" │ Parent: None │ └──▶ [TREE Object: Hash 4f1c...] (The Root Folder) │ ├── "index.html" ──▶ [BLOB Object: Hash 7e8d...] (Contains HTML text) │ └── "src/" ──▶ [TREE Object: Hash 2b9a...] (A Sub-Folder) └── "app.js" ──▶ [BLOB Object] */

Interview Questions

basic

  • Do Blobs store the filename (like `index.html`)?

intermediate

  • What does a Commit object point to?

Flash Cards

Question

Store filename?

Click to reveal answer
Answer

No! A Blob stores ONLY the raw data (the code). The filename (`index.html`) is stored inside the Tree object. This is why renaming a file is so fast in Git.

Question

Commit points to?

Click to reveal answer
Answer

A Commit points to exactly ONE root Tree (representing the entire project folder at that moment in time), and it also points to its Parent Commit (the commit that came before it).