Skip to content
rajin

09Working directory, Index and HEAD

core25–30 minHandbook pp. 23–24 Not started

Warm-up · from “Building a commit from scratch”

Does write-tree create a commit?

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

The problem

You stage version 2 of payment.txt, edit it again to version 3, then commit. Which version becomes history?

After this lesson you can

  • Distinguish the three states.

  • Inspect each independently.

  • Predict the result of staging and committing.

Key terms

Full glossary

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

  • Index · new in this lesson

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

  • Commit · from lesson 7

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

  • Tree · from lesson 6

    Directory snapshot mapping names, modes and object IDs.

  • Object ID · from lesson 5

    Hash-based identity of a serialized Git object.

  • HEAD · preview, covered in lesson 14

    Current symbolic branch reference or detached commit identity.

Visual mental model

Working tree
v3
Index
v2
HEAD snapshot
v1
Before committing: disk, staged content and the current snapshot can differ.

Build the mental model

The working tree holds editable files. The Index holds prepared path, mode and object-ID entries (the next normal commit's snapshot). HEAD identifies the checked-out commit, or an unborn branch before the first commit. These three states can differ independently. A normal commit reads the Index, not the most recent on-disk content.

SimulationThe three states of payment.txt

A simplified model for building intuition. It does not read your sandbox; use the terminal for real behaviour.

Under the hood

Use cat payment.txt for disk, git show :payment.txt for stage 0, and git show HEAD:payment.txt for the current commit. git status distinguishes changes to be committed from changes not staged. The Index also holds stat information for efficient checks and special stages during conflicts. The three trees is a teaching analogy: the Index is not itself a Git tree object, and HEAD is a reference.

Common mistake · important nuance

Commands such as git commit -a or git commit PATH have different staging semantics. In this lesson use plain git commit -m. The diagram shows the state before the final commit.

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