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.
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
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.
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
<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..Bas "what is new in B".git log main..featurelists the commits you would be adding if you mergedfeatureintomain. Swap the sides to see what you would pull in the other direction. A..Bis sugar for^A B. The same set can be writtenB --not Aor^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 trackingorigin/main.git log ..origin/mainlists what you would receive. - Three dots are symmetric.
A...BandB...Aselect the same commits, just in a different order. Use--left-rightto 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. diffwith three dots uses only one side's changes.git diff A...Bignores changes that landed onAafter 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..Bcan list commits from several branches. - Counting is cheap with
git rev-list --count A..Band does not print any commit text.