Git Working Tree, Index, and Commit

Git can distinguish the files you are editing, the contents chosen for the next commit, and the last recorded snapshot.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace one file
  2. Inspect both differences
  3. Observe three versions of one path at the same time
  4. Check the staged snapshot before saving it

Trace one file

Edit a note and stage its contents. Editing it again leaves the later changes in the working tree while the earlier version remains staged. A commit includes the staged snapshot under normal commit usage. See choosing a staged change.

Inspect both differences

Review the working-tree difference separately from the staged difference before recording work. Reading a diff helps identify which edits each comparison displays from those separate layers.[1]

Observe three versions of one path at the same time

A report starts with value one in the latest commit. Edit it to two, stage it, then edit it again to three. The index still requests two for the next snapshot while the working file has three. Inspect both differences before assuming what a commit will contain. See reading a diff.

HEAD version: count=1
Index version: count=2
Working tree version: count=3
Unstaged diff describes 2→3, staged diff describes 1→2

Check the staged snapshot before saving it

Ordinary committing without paths or auto-staging uses the index. A staged edit can coexist with unstaged edits to the same file. Verify both the intended committed contents and remaining local changes afterward.

References

  1. Scott Chacon and Ben Straub, Pro Git ↩