2016-10-03 131 views
11

当我运行git diff,输出始于:“git diff”中的“diff --git”输出是指什么?

diff --git a/foo/bar b/foo/bar 

如果我尝试运行普通的旧diff --git,我听说了--git选项不存在(很明显,我想,它会看起来很可笑要知道一个特定的DVCS的低级工具)。在man页面中也没有提及它。这是从哪里来的?

+0

确实令人困惑的是git如何以这种奇怪的方式包含这些命令。 –

+3

在这里添加特定的输出:https://github.com/git/git/commit/b58f23b38a9a9f28d751311353819d3cdf6a86da,其推理如下:http://www.gelato.unsw.edu.au/archives/ git/0505/3812.html – nos

+0

有人删除了它,但我最初有一个'osx'标签来表明这是''diffOS'随macOS提供的,而GNU工具可能* diff *呃。 – JHZ

回答

8

这是一个 “想象的diff选项”,用于指示它的不只是运行的输出读者diff命令。例如,在混帐自己的混帐回购协议:

$ git diff HEAD~1..HEAD | head 
diff --git Documentation/git.txt Documentation/git.txt 
index bd659c4..7913fc2 100644 
--- Documentation/git.txt 
+++ Documentation/git.txt 
@@ -43,6 +43,11 @@ unreleased) version of Git, that is available from the 'master' 
branch of the `git.git` repository. 
Documentation for older releases are available here: 

+* link:v2.10.0/git.html[documentation for release 2.10] 
+ 
$ 

diff命令本身,如果你使用相同的文件名调用它两次,会显示无显着差异。 git大概会创建对应于Documentation/git.txt的两个不同版本的临时文件,并将它们提供给diff - 但这些临时文件的名称不会有用。我认为git diff按摩diff的输出使其对读者更有意义。

跳水到Git的源代码,diff.c有硬作为一个字符串字面量字符串"diff --git"

strbuf_addf(&header, "%s%sdiff --git %s %s%s\n", line_prefix, meta, a_one, b_two, reset); 

而寻找到的diff.c的最早版本包含字符串的历史:

$ git log -n 1 b58f23b3 
commit b58f23b38a9a9f28d751311353819d3cdf6a86da 
Author: Junio C Hamano <[email protected]> 
Date: 2005-05-18 09:10:47 -0700 

    [PATCH] Fix diff output take #4. 

    This implements the output format suggested by Linus in 
    <[email protected]>, except the 
    imaginary diff option is spelled "diff --git" with double dashes as 
    suggested by Matthias Urlichs. 

    Signed-off-by: Junio C Hamano <[email protected]> 
    Signed-off-by: Linus Torvalds <[email protected]> 
$ 

推测<Pine.LNX...>是某个邮件列表中某个电子邮件消息的消息标识。无论如何,这个提交信息表明diff --git是一个“虚构差异选项”。

This email message,在评论中被nos引用,似乎是导致这种情况的讨论的一部分。

0

--git是指diff是以“git”diff格式。它不涉及和选项/usr/bin/diff命令您可以找到diff format文档的列表。其他格式有:

  • diff --combined
  • diff --cc
  • diff --summary