revisions#

See also: Pro Git - Revision Selection

Git uses various symbols to refer to specific commits (references) or ranges of commits.

Relative References#

Use these to move through the commit history starting from a specific point (like HEAD).

~ (Ancestor)#

Points to the n-th ancestor, following only the first parent of each commit.

  • HEAD~: The parent of HEAD.
  • HEAD~2: The grandparent (parent of the parent).
  • HEAD~<n>: The n-th ancestor.

^ (Parent)#

Points to the n-th parent of a commit. This is particularly useful for merge commits which have multiple parents.

  • HEAD^: The first parent (same as HEAD~).
  • HEAD^2: The second parent (the branch that was merged into the current branch).
  • HEAD^n: The n-th parent.

Tip: You can combine them, e.g., HEAD~3^2 (the second parent of the 3rd ancestor).

Commit Ranges#

Use these to specify a set of commits for commands like git log or git diff. Note that the behavior of .. and ... differs significantly between these two commands. You can also leave off one side of the syntax to have Git assume HEAD.

.. (Double-Dot)#

  • git log A..B: Shows commits reachable from B but not from A. This is the most common way to see what is on a branch that isn’t yet in your base branch. It is equivalent to ^A B.
  • git diff A..B: Shows the difference between the state of A and B. This is equivalent to git diff A B.

... (Triple-Dot)#

  • git log A...B: Shows the symmetric difference—commits reachable from either A or B, but not both.
  • git diff A...B: Shows the changes on B since it diverged from A. It compares the common ancestor of A and B with B. This is the standard way to review a feature branch’s changes relative to its base.

Summary Table#

Syntaxgit loggit diff
A..BRange (In B, not in A)Direct comparison (A vs B)
A...BSymmetric differenceBranch review (Ancestor of A/B vs B)

# git