Reference

Git

Inspect, save, combine and recover work with clear command effects.

Scope and conventions

Modern Git CLI, including switch and restore (Git 2.23+). Independent examples use illustrative paths and branch names. Inspect status and diffs before changing files or history. Commands below are reference material, not executed by this guide.

Inspect work

Working tree, index and history

Git

Working tree: files currently on disk. Index: the proposed next snapshot. HEAD: the current commit, usually reached through the checked-out branch.

Fragment

Git · Working tree, index and history
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git status --short
git diff
git diff --staged

git diff compares working tree with index; --staged compares index with HEAD.

Read short status columns

Git

In short status, the first column describes the index and the second the working tree. ?? means untracked. Conflicts have special combinations such as UU.

Fragment

Git · Read short status columns
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
# Illustrative output, not commands:
# M  staged.ts
#  M unstaged.ts
# MM edited-twice.ts
# ?? new.ts

Inspect a patch or a changed-file summary

Git

--stat summarizes changes. -- separates revisions/options from paths. A patch describes the compared snapshots, not necessarily every file on disk.

Fragment

Git · Inspect a patch or a changed-file summary
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git diff --stat
git diff -- src/main.ts
git diff --staged -- src/main.ts

Read commits and their patches

Git

log lists reachable history; show displays an object and, for a commit, its patch. --all includes refs beyond the current branch.

Fragment

Git · Read commits and their patches
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git log --oneline --graph --decorate --all
git show HEAD
git log -p -- src/main.ts

Understand revision expressions

Git

HEAD~2 follows first parents twice. HEAD^2 selects the second parent. A..B in log means commits reachable from B but not A.

Fragment

Git · Understand revision expressions
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git log main..feature
git diff main...feature

In diff, A...B compares the merge base with B; it is not the same meaning as log’s three-dot symmetric difference.

Trace a line without assuming causation

Git

blame attributes lines to commits. The last edit to a line is evidence of provenance, not proof that it caused a bug.

Fragment

Git · Trace a line without assuming causation
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git blame -L 10,30 -- src/main.ts
git log -S 'timeoutMs' -- src/main.ts

Narrow a regression by testing commits

Git

bisect searches between a known bad and good revision. Mark each checked-out candidate good or bad; reset returns to the original checkout.

Fragment

Git · Narrow a regression by testing commits
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git bisect start
git bisect bad
git bisect good KNOWN_GOOD_COMMIT
# Test the current candidate, then use one:
git bisect good
# Finish after the culprit is identified:
git bisect reset

KNOWN_GOOD_COMMIT is a placeholder. The test must consistently distinguish the behavior you are investigating; unbuildable commits may need skip.