Skip to content
rajin

06Trees and directory structures

core25–30 minHandbook pp. 17–18 Not started

Warm-up · from “Hashing and blob objects”

Does a blob store its filename?

No notes: write what you remember, then check. Recalling before reading is what makes it stick.

The problem

A blob knows nothing about filenames. How can Git reconstruct a folder with an executable file and two identical text files?

After this lesson you can

  • Read tree entries.

  • Explain nested directories and file modes.

  • Identify why normal Git ignores empty directories.

Key terms

Full glossary

Say what each term means, then open it to check.

  • Tree · new in this lesson

    Directory snapshot mapping names, modes and object IDs.

  • Object ID · from lesson 5

    Hash-based identity of a serialized Git object.

  • Blob · from lesson 5

    Object storing file contents without a filename.

  • Commit · preview, covered in lesson 7

    Object identifying a root tree, parent(s), metadata and message.

  • Index · preview, covered in lesson 9

    Prepared path-to-object entries, plus metadata and conflict stages.

Visual mental model

  1. Root tree
  2. src subtree
  3. README blobREADME.md
  4. app.txt blobsrc/app.txt
Each tree names its children; the tree structure reconstructs paths.

Build the mental model

A tree maps names to object IDs and modes. Common modes are 100644 for regular files, 100755 for executable files, 120000 for symbolic links, and 040000 for subtrees; 160000 is used for gitlinks. A root tree points to entries at the root. A subtree points to its own children. The tree stores the basename at its level rather than full paths.

Computed in your browser · exactBuild a tree from entries

Computed in your browser: the tree ID depends on every entry’s mode, name and object ID.

Under the hood

The Index lists full paths and modes; git write-tree builds the corresponding tree hierarchy. Git can represent an empty tree object, but normal add/commit workflows do not track empty directories as standalone items. Use a meaningful placeholder if the empty directory must exist after checkout. Git does not preserve arbitrary Unix permission bits, ownership or modification timestamps in trees.

Common mistake · important nuance

The object type shown by ls-tree is inferred from the mode; the binary tree format stores mode, name and raw object ID.

Move between parts freely. Completion counts only what you verify and answer.