什么是;diff——git“;以「;git diff“;提到
当我运行什么是;diff——git“;以「;git diff“;提到,git,Git,当我运行git diff时,输出以以下内容开始: diff --git a/foo/bar b/foo/bar 如果我尝试运行普通的老式diff--git,我会被告知--git选项不存在(显然,我想,一个低级工具了解特定的DVC似乎很愚蠢)。在man页面中也没有提到这一点。这是从哪里来的?这个--git意味着diff是“git”diff格式的。它不涉及/usr/bin/diff命令的选项,您可以找到文档列表。其他格式包括: diff——组合的 diff--cc diff--summary 这
git diff
时,输出以以下内容开始:
diff --git a/foo/bar b/foo/bar
如果我尝试运行普通的老式diff--git
,我会被告知--git
选项不存在(显然,我想,一个低级工具了解特定的DVC似乎很愚蠢)。在man
页面中也没有提到这一点。这是从哪里来的?这个--git
意味着diff是“git”diff格式的。它不涉及/usr/bin/diff
命令的选项,您可以找到文档列表。其他格式包括:
diff——组合的
diff--cc
diff--summary
diff
命令的输出。例如,在git自己的git回购中:
$ 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 <junkio@cox.net>
Date: 2005-05-18 09:10:47 -0700
[PATCH] Fix diff output take #4.
This implements the output format suggested by Linus in
<Pine.LNX.4.58.0505161556260.18337@ppc970.osdl.org>, except the
imaginary diff option is spelled "diff --git" with double dashes as
suggested by Matthias Urlichs.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
$
但是,
git-diff
没有使用它,至少在我尝试过的一个案例中,我在git源代码中没有看到对它的引用。正如Keith提到的,在GNU-diff中(使用diff-v
检查您的版本),您可以通过使用--label
获得git样式的补丁,如下所示:
备份中的单个文件
diff-u--label a/path/to/file.ext--label b/path/to/file.ext path/to/file.ext~path/to/file.ext
还是从标准时间
输出先前版本的命令diff-u——标签a/path/to/file.ext——标签b/path/to/file.ext-path/to/file.ext-to/file.ext
您可以在
find
等文件循环中使用这些命令,其中比较的一侧不存在,例如新文件,与/dev/null
相比,git如何以如此奇怪的方式包含这些命令确实令人困惑。这里添加了特定的输出:其原因隐藏在这里:有人删除了它,但我最初有一个osx
标记,表明这是macOS附带的diff
,GNU工具可能会有所不同。
'-L LABEL'
'--label=LABEL'
Use LABEL instead of the file name in the context format (*note
Context Format::) and unified format (*note Unified Format::)
headers. *Note RCS::.