【问题标题】:Spurious change when using git diff <base>...<feature>使用 git diff <base>...<feature> 时的虚假更改
【发布时间】:2015-08-25 08:39:54
【问题描述】:

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

这是一个普通 diff 的输出:

git diff upstream/develop feature script.sql

(无输出。)

这是“在特性分支上更改”的输出-三点运算符差异:

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 git-branch git-merge branching-and-merging


    【解决方案1】:

    来自git help diff

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

    这是查看任意两个之间的变化。

    ...

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

    此表单用于查看包含和直到第二个的分支上的更改,从两者的共同祖先开始。 “git diff A...B”等价于“git diff $(git-merge-base A B) B”。您可以省略 中的任何一个,这与使用 HEAD 的效果相同。

    ...

    然而,“差异”是关于比较两个端点,而不是范围,并且范围符号(“..”和“...”)并不意味着 git- 中“指定范围”部分中定义的范围转解析(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 之后的两个分支中。

    【讨论】:

      猜你喜欢
      • 2011-03-02
      • 2015-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-16
      • 2011-04-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多