Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Revisions and Pathspecs

Revision ranges: A..B and A...B

Reference for Git range syntax: what A..B and A...B select in log, rev-list and diff, why diff treats them differently, and how to read the results.

A range names a set of commits instead of a single one. A..B means "commits reachable from B but not from A": what B has that A lacks. A...B (three dots) means "commits reachable from either side but not from both": the commits that make the two histories differ, counted in both directions.

Ranges are understood by every command that walks history, such as git log, git rev-list, git shortlog, git cherry and git format-patch. git diff accepts the same spelling but gives the dots a different meaning, which is the most common source of confusion.

Terminal
git log A..B     # in B, not in A
git log A...B    # in A or B, not in both (symmetric difference)
git diff A..B    # same as: git diff A B
git diff A...B   # changes on B since the merge base of A and B

Try it

Bash Two dots versus three dots in log

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash The same dots mean something else in diff

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
<A>..<B>      # reachable from B, excluding everything reachable from A
<A>...<B>     # reachable from A or B, excluding what both reach
<A>..         # shorthand for A..HEAD
..<B>         # shorthand for HEAD..B
<A>...        # shorthand for A...HEAD
Form In log, rev-list and similar In diff
A..B Commits in B and not in A. Same as git diff A B: compare the two trees directly.
A...B Commits in A or B but not both (symmetric difference). Compare B with the merge base of A and B: what B changed since the fork.

Related options: --left-right marks each commit with < (only on the left side) or > (only on the right side); %m prints that mark in a custom format. --cherry-mark and --cherry-pick hide or flag commits whose patches are equivalent on both sides. --count with --left-right prints two numbers, the left-only and right-only counts.

Errors and edge cases: if a side is not a valid revision, Git reports unknown revision or path not in the working tree. If A and B have no common ancestor, A...B in diff fails with no merge base.

Usage notes

  • Read A..B as "what is new in B". git log main..feature lists the commits you would be adding if you merged feature into main. Swap the sides to see what you would pull in the other direction.
  • A..B is sugar for ^A B. The same set can be written B --not A or ^A B; see ^rev and --not. This form generalizes to more than two tips, which the dot syntax cannot do.
  • An omitted side means HEAD. git log origin/main.. lists your unpushed commits when you are on a branch tracking origin/main. git log ..origin/main lists what you would receive.
  • Three dots are symmetric. A...B and B...A select the same commits, just in a different order. Use --left-right to tell the two sides apart.
  • In diff, the dots are not about commits. Two dots are optional decoration and equal to naming both revisions. Three dots ask for the changes on one branch since it forked, which is what a pull request shows.
  • diff with three dots uses only one side's changes. git diff A...B ignores changes that landed on A after the fork. If you want both sides compared, use two dots.
  • A range is not a path. If a name is both a file and a revision, add -- before the paths: git log main..feature -- src/.
  • Merges are fine. Ranges are computed on the commit graph, so merged-in work counts as reachable. That is why A..B can list commits from several branches.
  • Counting is cheap with git rev-list --count A..B and does not print any commit text.