Skip to content
rajin

07Commit objects and immutability

core25–30 minHandbook pp. 19–20 Not started

Warm-up · from “Trees and directory structures”

Where is a filename stored?

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

The problem

A commit message has a typo. If you amend only that message, why does the commit ID change even though every project file is identical?

After this lesson you can

  • Inspect a commit payload.

  • Explain parent links and metadata.

  • Distinguish commits from trees.

Key terms

Full glossary

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

  • Commit · new in this lesson

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

  • Tree · from lesson 6

    Directory snapshot mapping names, modes and object IDs.

  • Ref · from lesson 3

    Name identifying an object; branch refs usually identify commits.

Visual mental model

  1. Commit C
  2. Root tree T
  3. Parent P
  4. Author / message
A commit identifies a tree and parent(s), and contains its own metadata.

Build the mental model

A commit contains a root tree ID, zero or more parent IDs, author and committer identities and timestamps, and a message. A root commit has no parents; a typical commit has one; a merge can have multiple. A commit object may contain extra headers such as a signature. Its identity is calculated from the entire serialized object.

Computed in your browser · exactChange only the message

Computed in your browser: edit the message and watch the commit ID change while the tree ID stays.

Under the hood

Existing objects are immutable in normal Git operations. Amending creates a replacement commit (if the payload differs) and moves the current ref. The original object may remain accessible until it becomes unreachable and is eventually collected. Two repositories can create identical commit IDs if every byte of the commit payload and hash format matches; timestamps and identities often make them differ.

Common mistake · important nuance

A commit is not a branch and does not contain its branch name. Multiple refs can identify the same commit.

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