Study notes · 10% of the exam

History, Diffs, Refs and the Object Model

Git history is a graph of immutable, content-addressed objects. Knowing how refs, revision syntax and range notation walk that graph lets you answer "what changed, where and when" precisely.

Key points

  1. 1

    Objects: blobs hold content, trees map names to blobs and subtrees, commits point to one tree plus parents; IDs are hashes, so identical content is stored once.

  2. 2

    Branches are refs holding one commit ID; HEAD is usually a symbolic ref to a branch and becomes "detached" when it holds a commit ID directly.

  3. 3

    ~n walks first parents; ^n picks the n-th parent of a merge; ref@{n} reads the reflog; @{u} is the upstream and @{-1} the previous branch.

  4. 4

    In log, A..B is "in B, not in A" and A...B is the symmetric difference. In diff, A..B equals A B and A...B diffs from the merge base to B.

  5. 5

    git diff is working tree vs index, --staged is index vs HEAD, and git diff HEAD is working tree vs HEAD.

  6. 6

    -S finds commits that change how often a string occurs; -G finds patches with matching lines; -L traces a line range or function; --follow tracks one file across renames.

  7. 7

    --first-parent shows the mainline with one merge per feature; --since filters on committer date, which rebases reset.

Common traps

  • git diff main..feature is not what a pull request shows; use main...feature.

  • HEAD~2 and HEAD^2 are different commits whenever merges are involved.

  • Commits made on a detached HEAD are not deleted when you switch away, but they become unreachable and expire with the reflog.

Test yourself on History, Diffs, Refs and the Object Model

Ten questions, with the answer and explanation after each one.