Using Commit Ranges with Git Log
When you’re using commit ranges like ..
and ...
with git log
, the difference between them is that, for branches A and B,
git log A..B
will show you all of the commits that B has that A doesn’t have, while
git log A...B
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 Useful
You 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:
$ git log --oneline --decorate --left-right --graph master...origin/master
< 1794bee (HEAD, master) Derp some more
> 6e6ce69 (origin/master, origin/HEAD) Add hello.txt
In the above output, you’ll see the commits that belong to master
are prefixed with <
, while commits that belong to origin/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
- Pro Git § 6.1 Git Tools – Revision Selection – Commit Ranges