Some Git commands take commit ranges and one valid syntax is to separate two commit names with two dots ..
, and another syntax uses three dots ...
.
What are the differences between the two?
Some Git commands take commit ranges and one valid syntax is to separate two commit names with two dots ..
, and another syntax uses three dots ...
.
What are the differences between the two?
It depends on whether you're using a
log
command or adiff
command. In thelog
case, it's in theman git-rev-parse
documentation:Which basically means that you'll get all commits that are in either of the two branches, but not in both.
In the
diff
case, it's in theman git-diff
documentation:Which is a bit fuzzy. Basically it means it shows only the differences in that branch compared to another branch: it looks for the last common commit with the first committish you gave it, and then diffs the second committish to that. It's an easy way to see what changes are made in that branch, compared to this branch, without taking notice of changes in this branch only.
The
..
is somewhat simpler: In thegit-diff
case, it's the same as agit diff A B
and just diffs A against B. In thelog
case, it shows all commits that are in B but not in A.Using Commit Ranges with Git Log
When you're using commit ranges like
..
and...
withgit log
, the difference between them is that, for branches A and B,will show you all of the commits that B has that A doesn't have, while
will show you both the commits that A has and that B doesn't have, and the commits that B has that A doesn't have, or in other words, it will filter out all of the commits that both A and B share, thus only showing the commits that they don't both share.
Visualization with Venn Diagrams & Commit Trees
Here is a visual representation of
git log A..B
. The commits that branch B contains that don't exist in A is what is returned by the commit range, and is highlighted in red in the Venn diagram, and circled in blue in the commit tree:These are the diagrams for
git log A...B
. Notice that the commits that are shared by both branches are not returned by the command:Making the Triple-Dot Commit Range
...
More UsefulYou can make the triple-dot commit range
...
more useful in a log command by using the--left-right
option to show which commits belong to which branch:In the above output, you'll see the commits that belong to
master
are prefixed with<
, while commits that belong toorigin/master
are prefixed with>
.Using Commit Ranges with Git Diff
Someday I might add my own explanation for how the commit ranges work with
git diff
, but for now, you might want to check out What are the differences between double-dot ".." and triple-dot "..." in Git diff commit ranges?.See Also