2016-10-03 140 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