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 ofHEAD.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 asHEAD~).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 fromBbut not fromA. 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 ofAandB. This is equivalent togit diff A B.
... (Triple-Dot)#
git log A...B: Shows the symmetric difference—commits reachable from eitherAorB, but not both.git diff A...B: Shows the changes onBsince it diverged fromA. It compares the common ancestor ofAandBwithB. This is the standard way to review a feature branch’s changes relative to its base.
Summary Table#
| Syntax | git log | git diff |
|---|---|---|
A..B | Range (In B, not in A) | Direct comparison (A vs B) |
A...B | Symmetric difference | Branch review (Ancestor of A/B vs B) |