What are the differences between double-dot ".." and triple-dot "..." in Git commit ranges?

Viewed 88347

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?

4 Answers

It depends on whether you're using a log command or a diff command. In the log case, it's in the man git-rev-parse documentation:

To exclude commits reachable from a commit, a prefix ^ notation is used. E.g. ^r1 r2 means commits reachable from r2 but exclude the ones reachable from r1.

This set operation appears so often that there is a shorthand for it. When you have two commits r1 and r2 (named according to the syntax explained in SPECIFYING REVISIONS above), you can ask for commits that are reachable from r2 excluding those that are reachable from r1 by "^r1 r2" and it can be written as "r1..r2".

A similar notation "r1...r2" is called symmetric difference of r1 and r2 and is defined as "r1 r2 --not $(git merge-base --all r1 r2)". It is the set of commits that are reachable from either one of r1 or r2 but not from both.

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 the man git-diff documentation:

  git diff [--options] <commit>...<commit> [--] [<path>...]

      This form is to view the changes on the branch containing and up to
      the second <commit>, starting at a common ancestor of both
      <commit>. "git diff A...B" is equivalent to "git diff
      $(git-merge-base A B) B". You can omit any one of <commit>, which
      has the same effect as using HEAD instead.

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 the git-diff case, it's the same as a git diff A B and just diffs A against B. In the log case, it shows all commits that are in B but not in A.

I think the biggest source of confusion about two dots versus three dots is because when used with git diff it's sort of the opposite of when used with git log.

Please see the other answers, or the actual documentation, or numerous blog posts for the exact details, but I find these simple statements to work well for conveying the right idea:

git log  A..B   # Show me commits only on B.
git log  A...B  # Show me commits only on A or only on B.
git diff A..B   # Show me changes only on A or only on B.
git diff A...B  # Show me changes only on B.

This is a bit confusing = So here is a how it is actually for this flow

      A---B---C topic
     /
D---E---F---G master

https://github.com/alexcpn/gitdiffs/pull/2/commits https://github.com/alexcpn/gitdiffs/pull/1/commits

Git Log Behaviour

1 > git log --oneline --graph topic...main
* 9411a8b (HEAD -> main) G
* 3a567aa F
* aad429f (topic) C
* 6b1eb5a B
* d65c129 A
topic
D
E
A
B
C
main
D
E
F
G
In topic and main, but not in
both
2 git log --oneline --graph main...topic
* 9411a8b (HEAD -> main) G
* 3a567aa F
* aad429f (topic) C
* 6b1eb5a B
* d65c129 A
topic
D
E
A
B
C
main
D
E
F
G
Same as above
3 git log --oneline --graph topic..main
* 9411a8b (HEAD -> main) G
* 3a567aa F
topic
D
E
A
B
C
main
D
E
F
G
In main,but not in topic
4 git log --oneline --graph main..topic
* aad429f (topic) C
* 6b1eb5a B
* d65c129 A
topic
D
E
A
B
C
main
D
E
F
G
In topic, but not in main

Git Diff behaviour

1 git diff topic..main
D
E
-A
-B
-C
+F
+G
topic
D
E
A
B
C
main
D
E
F
G
what's in main
whats not in main compared
to topic
2 git diff main..topic
D
E
-F
-G
+A
+B

+C
topic
D
E
A
B
C
main
D
E
F
G
whats in topic
whats not in topic compared to
main
3 git diff main...topic
D
E (you may get newline here)
+A
+B
+C
topic
D
E
A
B
C
main
D
E
F
G
In topic,but not in main
4 git diff topic...main
D
E
+F
+G
topic
D
E
A
B
C
main
D
E
F
G
In main, but not in topic
Related