I have seen that whenever we create a diff we use the following command.
diff -Naur old new > file.patch
I was wondering what is this -Naur
switch. How this name came and what exactly is speciality about it? Off course, I can do the diff program without Naur option to discover the difference. But, I am looking for some more information on it.
I realize this is an old question that already has an answer, but it did not go into the depth I was personally looking for. So I did my own research which I am posting below:
I was wondering what is this
-Naur
switch.
This official GNU site on creating patches site explains it quite well; -Naur
is a series of four (4) diff
command switches that break down as follows:
-N
: Treat absent files as empty; Allows the patch create and remove files.-a
: Treat all files as text; Allows the patch update non-text (aka: binary) files.-u
: Set the default 3 lines of unified context; This generates useful time stamps and context.-r
: Recursively compare any subdirectories found; Allows the patch to update subdirectories.The -u
flag confused me a but, but the Wikipedia page on the diff utility has a nice explanation; bold emphasis is mine:
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.
Which all basically means the -u
flag allows diff to output patch data in a commonly known, recognized and accepted format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With