Skip to content
rajin

10What add and commit actually do

core25–30 minHandbook pp. 25–26 Not started

Warm-up · from “Working directory, Index and HEAD”

What is the Index for?

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

The problem

A file is staged and the laptop crashes before commit. Did Git ever store the content? Follow the path from the working tree to the object database.

After this lesson you can

  • Trace normal add and commit.

  • Inspect staged object IDs.

  • Explain how staged content may survive without a commit.

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.

  • Blob · from lesson 5

    Object storing file contents without a filename.

  • HEAD · preview, covered in lesson 14

    Current symbolic branch reference or detached commit identity.

  • Reachability · preview, covered in lesson 27

    Whether an object can be reached by traversing links from roots.

Visual mental model

  1. Disk bytes
  2. Blob + Index entrygit add
  3. Tree + commitgit commit
  4. Branch ref

Build the mental model

When git add stages a regular file, Git computes its content object ID (after configured filters), writes or reuses the blob, then updates the Index entry. A plain commit writes trees from the Index, creates the commit object with the previous HEAD as parent if it exists, and updates the current ref. Git also maintains reflogs when configured. Hooks or signing may affect whether a commit succeeds.

SimulationAdd stores content, commit records it

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

Under the hood

The Index is a binary data structure; git ls-files --stage prints mode, object ID, stage and path. Stage 0 is the normal resolved entry. If the file is changed after git add, the Index keeps the earlier staged blob until another staging operation updates it. An object may exist without being reachable from a commit; do not treat this as a reliable backup.

Common mistake · important nuance

Do not confuse tracking a path with storing a new copy every time. An identical blob can already exist.

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