【问题标题】:git diff produces different results when used on full repo vs a single filegit diff 在完整 repo 和单个文件上使用时会产生不同的结果
【发布时间】:2021-06-22 15:41:27
【问题描述】:

我们尝试使用两个moodle版本之间的更改创建一个补丁文件。

这就是我们所做的

$ git clone https://github.com/moodle/moodle.git
$ cd moodle
$ git diff  v3.8.1...v3.11.0 > /tmp/upgrade3_8_1__3_11_0.patch

但是当我们验证这个文件时,补丁看起来很奇怪:

$ grep " a/version.php" /tmp/upgrade3_8_1__3_11_0.patch -A 13
diff --git a/version.php b/version.php
index 6806d4e84d7..9c4d48bbb41 100644
--- a/version.php
+++ b/version.php
@@ -29,9 +29,9 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$version  = 2019111800.00;              // 20191118      = branching date YYYYMMDD - do not modify!
+$version  = 2021051700.00;              // 20210517      = branching date YYYYMMDD - do not modify!
                                     //         RR    = release increments - 00 in DEV branches.
                                     //           .XX = incremental changes.
-$release  = '3.8 (Build: 20191118)'; // Human-friendly version name
-$branch   = '38';                       // This version's branch.
+$release  = '3.11 (Build: 20210517)';// Human-friendly version name
+$branch   = '311';                      // This version's branch.

问题:

应该是

-$release  = '3.8.1 ...

代替

-$release  = '3.8 ...

如果我们只在 version.php 上执行命令,它会产生预期的结果:

$ git diff v3.8.1..v3.11.0 version.php
diff --git a/version.php b/version.php
index 93c45b4ab93..9c4d48bbb41 100644
--- a/version.php
+++ b/version.php
@@ -29,9 +29,9 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$version  = 2019111801.00;              // 20191118      = branching date YYYYMMDD - do not modify!
+$version  = 2021051700.00;              // 20210517      = branching date YYYYMMDD - do not modify!
                                     //         RR    = release increments - 00 in DEV branches.
                                     //           .XX = incremental changes.
-$release  = '3.8.1 (Build: 20200113)'; // Human-friendly version name
-$branch   = '38';                       // This version's branch.
+$release  = '3.11 (Build: 20210517)';// Human-friendly version name
+$branch   = '311';                      // This version's branch.
 $maturity = MATURITY_STABLE;             // This version's maturity level.

怎么可能?

我们怎样才能创建正确的补丁?

Sidenode:我们甚至有一个 - 不可重现的案例 - git diff v3.8.1..v3.11.0 version.php 也显示了错误的结果。输出不应该是确定性的吗?是否依赖于当前分支?

$ git --version
git version 2.25.1

这是之前配置的:

git config diff.renameLimit 999999

【问题讨论】:

    标签: git diff moodle patch


    【解决方案1】:

    您使用的是 3 个点 ...,这与使用 .. 不同。可能这 2 个修订的共同祖先是 3.8,这就是为什么您会看到这样的修订集。

    而且,在比较文件时,您使用的是..。试试...,你会得到同样的“unexpected”结果。

    【讨论】:

    • 这就解释了为什么我在git diff v3.8.1..v3.11.0 version.php 上得到了不同的结果——我曾经用树点使用过它,但看不到这一点。
    • 请注意,Git 项目人员正试图说服人们从git diff A..B 迁移到git diff A B。它的作用完全相同,但 (1) 读起来更好, (2) 短了一个完整的字符(非常重要?)。
    猜你喜欢
    • 2017-04-12
    • 1970-01-01
    • 1970-01-01
    • 2019-03-05
    • 1970-01-01
    • 1970-01-01
    • 2014-01-28
    • 2012-11-17
    相关资源
    最近更新 更多