diff 和 git diff 创建的 patches/files 有什么区别?
What differences are in the patches/files created by diff and git diff?
我想知道 diff
和 git-diff
创建的 files/patches 的格式有什么不同。
我知道在 diff
中有 3 个("normal"、"compact" -c
和 "unified" -u
一个)。
然而可能存在一些差异,在某些情况下您不能自由交换 git diff
和 diff
。所以:
- 是否可以对同一个文件使用
git diff
和diff
取决于什么?
- 格式之间有什么区别?
- 如果不能交换命令(参见 1.),如何将文件转换为其他格式以便可以将它们与其他命令一起使用?
- 如果可以交换命令(见 1.):是否推荐这样做?
- 这两个命令创建的文件还有其他显着差异吗?
- On what does it depend whether you can use
git diff
and diff
for the same file?
只要文件在 git 存储库工作树中,那么您就可以使用 git diff
来显示该文件的更改(针对 git 回购,如索引或 blob objects).
这与'diff
'不同,它比较文件(这意味着你需要两个文件,而不是像git diff 中使用的 git回购)
如hvd points out in the comments:
You can use 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
- And what are the differences between the formats?
git diff
可以模拟任何 diff 格式(统一,原始,...)。
它也有 git-specific 格式 (--summary
, --stat
, ...)
另请参阅:
A git diff
将包含 git header,以及 "similarity index".
每个差异块的 hunks 显示为 very similar to a diff -u.
- 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?
您可以将 git diff
转换为原始格式,或使用原始格式进行修补:--patch-with-raw
.
反过来是可能的:you can apply a diff to a git repo.
- If you can exchange the commands (see 1.): Is it even recommend to do so?
如果您没有安装 git(参见 the previous example)
- Are there any other notable differences in the files created by the two commands?
否:应用 diff
或 git diff
生成的补丁的结果应该是相同的。
我想知道 diff
和 git-diff
创建的 files/patches 的格式有什么不同。
我知道在 diff
中有 3 个("normal"、"compact" -c
和 "unified" -u
一个)。
然而可能存在一些差异,在某些情况下您不能自由交换 git diff
和 diff
。所以:
- 是否可以对同一个文件使用
git diff
和diff
取决于什么? - 格式之间有什么区别?
- 如果不能交换命令(参见 1.),如何将文件转换为其他格式以便可以将它们与其他命令一起使用?
- 如果可以交换命令(见 1.):是否推荐这样做?
- 这两个命令创建的文件还有其他显着差异吗?
- On what does it depend whether you can use
git diff
anddiff
for the same file?
只要文件在 git 存储库工作树中,那么您就可以使用 git diff
来显示该文件的更改(针对 git 回购,如索引或 blob objects).
这与'diff
'不同,它比较文件(这意味着你需要两个文件,而不是像git diff 中使用的 git回购)
如hvd points out in the comments:
You can use
git diff
outside any work tree and pass it two files.
So you can usegit diff
in pretty much any situation you can usediff
.
The reverse is not true
git diff --color-words --no-index file1 file2
- And what are the differences between the formats?
git diff
可以模拟任何 diff 格式(统一,原始,...)。
它也有 git-specific 格式 (--summary
, --stat
, ...)
另请参阅:
A git diff
将包含 git header,以及 "similarity index".
每个差异块的 hunks 显示为 very similar to a diff -u.
- 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?
您可以将 git diff
转换为原始格式,或使用原始格式进行修补:--patch-with-raw
.
反过来是可能的:you can apply a diff to a git repo.
- If you can exchange the commands (see 1.): Is it even recommend to do so?
如果您没有安装 git(参见 the previous example)
- Are there any other notable differences in the files created by the two commands?
否:应用 diff
或 git diff
生成的补丁的结果应该是相同的。