mzedeler
mzedeler

Reputation: 4381

Spurious change when using git diff <base>...<feature>

Github seems to use the triple dot comparison on pull requests, which tricked me today by showing a spurious change between a feature and the base branch.

Here is the base branch (abbreviated):

git show upstream/develop:script.sql
 FOR field IN (
         [001*a], [001*d], [001*y], [001*x], [001*z],
         [004*a],
         [008*a], [008*d], [008*j], [008*l], [008*o],
         [009*a], [009*b], [009*g], [009*x], [009*u],
         [041*a], [041*c],

Here is the feature branch (abbreviated):

git show feature:script.sql
 FOR field IN (
         [001*a], [001*d], [001*y], [001*x], [001*z],
         [004*a],
         [008*a], [008*d], [008*j], [008*l], [008*o],
         [009*a], [009*b], [009*g], [009*x], [009*u],
         [041*a], [041*c],

Here is the output from a plain diff:

git diff upstream/develop feature script.sql

(No output.)

Here is the output from "changed on feature branch"-triple dot operator diff:

git diff upstream/develop...feature script.sql
  FOR field IN (
          [001*a], [001*d], [001*y], [001*x], [001*z],
+         [004*a],
          [008*a], [008*d], [008*j], [008*l], [008*o],

Why?

There is no change on this line. Adding -w shouldn't be necessary since the plain diff above was run without it and reported no change.

Upvotes: 0

Views: 120

Answers (1)

joran
joran

Reputation: 2893

From git help diff

git diff [--options] [--] [...]

This is to view the changes between two arbitrary < commit >.

...

git diff [--options] ... [--] [...]

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

...

However, "diff" is about comparing two endpoints, not ranges, and the range notations (".." and "...") do not mean a range as defined in the "SPECIFYING RANGES" section in git-rev-parse(1)

Assuming you have two branches

A-B-C-D (branch1)
   \
    E-F (branch2) 

git diff branch1 branch2 myfile will give you a diff between the file content in D and F.

git diff branch1...branch2 will give you diff between the file content in B and F.

In your case the [004*a], may have been included in both branches, after B.

Upvotes: 1

Related Questions