diff和git diff创建的补丁/文件有什么区别? [英] What differences are in the patches/files created by diff and git diff?

查看:232
本文介绍了diff和git diff创建的补丁/文件有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道由diffgit-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 diffdiff.所以:

However there may be some differences and in some situations you cannot freely exchange git diffand diff. So:

  1. 对于同一文件是否可以使用git diffdiff取决于什么?
  2. 这些格式之间有什么区别?
  3. 如果无法交换命令(请参阅1.),如何将文件转换为其他格式,以便可以将其与其他命令一起使用?
  4. 如果您可以交换命令(请参阅1.):甚至建议这样做吗?
  5. 两个命令创建的文件是否还有其他显着差异?
  1. On what does it depend whether you can use git diffand diff for the same file?
  2. And what are the differences between the formats?
  3. 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?
  4. If you can exchange the commands (see 1.): Is it even recommend to do so?
  5. Are there any other notable differences in the files created by the two commands?

推荐答案

  1. 对于同一文件是否可以使用git diffdiff取决于什么?
  1. On what does it depend whether you can use git diff and diff 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 指出

您可以在任何工作树之外使用git diff并将其传递给两个文件.
因此,几乎可以在任何情况下使用diff的情况下使用git diff.
反之亦然

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


  1. 这些格式之间有什么区别?

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. 如果无法交换命令(请参阅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. 如果您可以交换命令(请参阅1.):甚至建议这样做吗?

这是如果您尚未安装git(请参见上一个示例)

It is if you don't have git installed (see the previous example)

  1. 两个命令创建的文件是否还有其他显着差异?

否:应用由diffgit diff生成的补丁的结果应该相同.

No: the result of applying a patch generated by a diff or a git diff should be the same.

这篇关于diff和git diff创建的补丁/文件有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆