diff和git diff创建的补丁/文件有什么区别? [英] What differences are in the patches/files created by diff and git diff?
问题描述
我想知道由diff
和git-diff
创建的文件/补丁格式有什么区别.
我知道在diff
中有3个(正常",紧凑" -c
一个和统一" -u
一个).
I wonder what differences are in the format of the files/patches created by diff
and git-diff
.
I know in diff
there are 3 (the "normal", the "compact" -c
one and the "unified" -u
one).
但是,可能会有一些差异,在某些情况下,您不能自由交换git diff
和diff
.所以:
However there may be some differences and in some situations you cannot freely exchange git diff
and diff
. So:
- 对于同一文件是否可以使用
git diff
和diff
取决于什么? - 这些格式之间有什么区别?
- 如果无法交换命令(请参阅1.),如何将文件转换为其他格式,以便可以将其与其他命令一起使用?
- 如果您可以交换命令(请参阅1.):甚至建议这样做吗?
- 两个命令创建的文件是否还有其他显着差异?
- On what does it depend whether you can use
git diff
anddiff
for the same file? - And what are the differences between the formats?
- If you cannot exchange the commands (see 1.) how can you convert the files into the other format so that you can use them with the other command?
- If you can exchange the commands (see 1.): Is it even recommend to do so?
- Are there any other notable differences in the files created by the two commands?
推荐答案
- 对于同一文件是否可以使用
git diff
和diff
取决于什么?
- On what does it depend whether you can use
git diff
anddiff
for the same file?
如果文件位于git repo工作树中,则可以使用git diff
显示该文件的更改(与git repo引用的文件相同,如index或blob对象) .
这与" diff
"不同,后者比较文件(这意味着您需要两个文件,而不仅仅是在git repo中使用时的git diff中的一个文件)
Simply if the file is in a git repo working tree, then you would be able to use git diff
to show changes for that file (against the same file as referenced by the git repo, like the index or blob objects).
This differs from 'diff
', which compares files (meaning you need two files, not just one as in git diff when used in a git repo)
hvd 指出
您可以在任何工作树之外使用 You can use
git diff
并将其传递给两个文件.
因此,几乎可以在任何情况下使用diff
的情况下使用git diff
.
反之亦然
git diff
outside any work tree and pass it two files.
So you can use git diff
in pretty much any situation you can use diff
.
The reverse is not true git diff --color-words --no-index file1 file2
- 这些格式之间有什么区别?
git diff
可以模拟任何diff格式(统一,原始,...).
它还具有特定于git的格式(--summary
,--stat
,...)
git diff
can emulate any diff format (unified, raw, ...).
It has git-specific format as well (--summary
, --stat
, ...)
另请参阅:
A git diff
将包含git标头,其中包含相似性索引".
每个差异块的块显示为非常类似于差异-u .
A git diff
will include a git header, with a "similarity index".
The hunks displays for each chunk of diffs are very similar to a diff -u.
- 如果无法交换命令(请参阅1.),如何将文件转换为其他格式,以便可以将其与其他命令一起使用?
您可以将git diff
转换为原始格式,也可以使用原始格式进行修补:--patch-with-raw
.
可能是相反的情况:您可以将diff应用于git repo .
You can convert a git diff
in a raw format, or patch with raw: --patch-with-raw
.
The reverse is possible: you can apply a diff to a git repo.
- 如果您可以交换命令(请参阅1.):甚至建议这样做吗?
这是如果您尚未安装git(请参见上一个示例)
It is if you don't have git installed (see the previous example)
- 两个命令创建的文件是否还有其他显着差异?
否:应用由diff
或git diff
生成的补丁的结果应该相同.
No: the result of applying a patch generated by a diff
or a git diff
should be the same.
这篇关于diff和git diff创建的补丁/文件有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!