Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

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.

like image 558
user439199 Avatar asked Jul 25 '26 23:07

user439199


1 Answers

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!

like image 101
Eugene Sajine Avatar answered Jul 27 '26 18:07

Eugene Sajine