user439199
user439199

Reputation: 397

What is the difference between git diff origin/master ... origin/branch and git diff origin/master...origin/branch?

Git diff seems to return different changes when comparing:

git diff origin/master ... origin/branch
git diff origin/master...origin/branch

What's the difference between the two? For those that can't see the difference in the first command, the ... is buffered by spaces.

Upvotes: 3

Views: 3029

Answers (2)

Eugene Sajine
Eugene Sajine

Reputation: 8200

Usually the "dots" notation is for specifying ranges and full doc on that is available in git log --help section "Specifying Revisions" and mostly used for listings like git log.

Briefly speaking you have two branches started from commit a:

a - b - c (master)
\d - e (topic)

git log master..topic will show you commits that are reachable from topic but not reachable from master, effectively "d" and "e"

git log topic..master will show you commits that are reachable from master but not reachable from topic, effectively "b" and "c"

Now git log master...topic (note three dots) will show you all commits that are reachable from either master or topic but not from both, effectively b,c,d and e

The diff though is working with two points of history, not the ranges so for example the notation

git diff topic master

or

git diff topic..master

should return the same result, i.e. the diff between the tips of the branches specified The three dots notation

git diff topic...master

should show the changes that occurred in master since the topic branch was forked off of it

As Jan pointed out the notation with the three dots surrounded by spaces is understood by git as the difference between the tips of the branches (like no dots or two dots) in case when HEAD is pointing to the same commit as one of the branches of interest. In cases when HEAD is neither topic or master it will result in three way diff.

Hope that helps!

Upvotes: 5

Jan Hudec
Jan Hudec

Reputation: 76316

The correct syntax is without spaces and does diff from common ancestor to the right branch.

With spaces it should be an error, because ... is neither revision nor path, but the argument parser takes it as synonym for HEAD. Probably side-effect of the fact, that ...branch means HEAD...branch and branch... means branch...HEAD. Together with the fact that git diff can take any number of arguments and produces n-way diffs when given more than 2 distinct arguments. I've checked and indeed git diff A ... B produces a 3-way diff when neither A nor B point to the same revision as HEAD.

Upvotes: 2

Related Questions