gpt4 book ai didi

linux - diff 程序中的 -Naur 是什么?

转载 作者:IT王子 更新时间:2023-10-29 00:49:57 27 4
gpt4 key购买 nike

我已经看到,每当我们创建差异时,我们都会使用以下命令。

diff -Naur old new > file.patch

我想知道这个 -Naur 开关是什么。这个名字是怎么来的,它有什么特别之处?当然,我可以在没有 Naur 选项的情况下执行 diff 程序来发现差异。但是,我正在寻找有关它的更多信息。

最佳答案

我意识到这是一个已经有了答案的老问题,但它并没有深入到我个人寻找的深度。所以我做了自己的研究,我在下面发布:

I was wondering what is this -Naur switch.

official GNU site on creating patches site解释得很好; -Naur 是一系列四 (4) 个 diff 命令开关,分解如下:

  • -N:将不存在的文件视为空文件;允许补丁创建和删除文件。
  • -a:将所有文件视为文本;允许补丁更新非文本(又名:二进制)文件。
  • -u:设置统一上下文默认3行;这会生成有用的时间戳和上下文。
  • -r:递归比较找到的任何子目录;允许补丁更新子目录。

-u 标志让我很困惑,但是 the Wikipedia page on the diff utility有很好的解释;大胆强调是我的:

The unified format (or unidiff) inherits the technical improvements made by the context format, but produces a smaller diff with old and new text presented immediately adjacent. Unified format is usually invoked using the "-u" command line option. This output is often used as input to the patch program. Many projects specifically request that "diffs" be submitted in the unified format, making unified diff format the most common format for exchange between software developers.

Unified context diffs were originally developed by Wayne Davison in August 1990 (in unidiff which appeared in Volume 14 of comp.sources.misc). Richard Stallman added unified diff support to the GNU Project's diff utility one month later, and the feature debuted in GNU diff 1.15, released in January 1991. GNU diff has since generalized the context format to allow arbitrary formatting of diffs.

The format starts with the same two-line header as the context format, except that the original file is preceded by "---" and the new file is preceded by "+++". Following this are one or more change hunks that contain the line differences in the file. The unchanged, contextual lines are preceded by a space character, addition lines are preceded by a plus sign, and deletion lines are preceded by a minus sign.

这基本上意味着 -u 标志允许 diff 以众所周知的、公认的和接受的格式输出补丁数据。

关于linux - diff 程序中的 -Naur 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19805203/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com