使用 git diff <base>...<feature> 时的虚假更改

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

Github 似乎在拉取请求上使用三点比较,今天通过显示功能和基本分支之间的虚假更改来欺骗我。

这里是基础分支(缩写):

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],

这是功能分支(缩写):

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],

这是普通差异的输出:

git diff upstream/develop feature script.sql

(无输出。)

这是 "changed on feature branch"-三点运算符 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],

为什么?

这一行没有变化。添加 -w 应该是不必要的,因为上面的普通差异是 运行 没有它并且报告没有变化。

来自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)

假设你有两个分支

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

git diff branch1 branch2 myfile 会给你 D 和 F 文件内容的差异。

git diff branch1...branch2 会给你 B 和 F 中文件内容的差异。

在您的情况下,[004*a], 可能已包含在 B 之后的两个分支中。