Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Diff
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Unified format === The ''unified format'' (or ''unidiff'')<ref>{{Cite web|url=https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html|title=Detailed Description of Unified Format|website=GNU Diffutils (version 3.7, 7 January 2018)|access-date=29 January 2020|archive-date=18 January 2020|archive-url=https://web.archive.org/web/20200118142136/http://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html|url-status=live}}</ref><ref>{{Cite web|url=https://www.artima.com/weblogs/viewpost.jsp?thread=164293|title=Unified Diff Format|last=van Rossum|first=Guido|website=All Things Pythonic|access-date=2020-01-29|archive-date=2019-12-25|archive-url=https://web.archive.org/web/20191225234517/https://www.artima.com/weblogs/viewpost.jsp?thread=164293|url-status=live}}</ref> 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 "<code>-u</code>" [[command-line option]]. This output is often used as input to the [[patch (Unix)|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|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 (computing)|header]] as the context format, except that the original file is preceded by "<samp>---</samp>" and the new file is preceded by "<samp>+++</samp>". 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]]. A hunk begins with '''range information''' and is immediately followed with the line additions, line deletions, and any number of the contextual lines. The range information is surrounded by double [[at sign]]s, and combines onto a single line what appears on two lines in the context format ([[#Context format|above]]). The format of the range information line is as follows: @@ -l,s +l,s @@ ''optional section heading''<!-- <syntaxhighlight lang="text"> ruins the italics --> The hunk range information contains two hunk ranges. The range for the hunk of the original file is preceded by a minus symbol, and the range for the new file is preceded by a plus symbol. Each hunk range is of the format ''l,s'' where ''l'' is the starting line number and ''s'' is the number of lines the change hunk applies to for each respective file. In many versions of GNU diff, each range can omit the comma and trailing value ''s'', in which case ''s'' defaults to 1. Note that the only really interesting value is the ''l'' line number of the first range; all the other values can be computed from the diff. The hunk range for the original should be the sum of all contextual and deletion (including changed) hunk lines. The hunk range for the new file should be a sum of all contextual and addition (including changed) hunk lines. If hunk size information does not correspond with the number of lines in the hunk, then the diff could be considered invalid and be rejected. Optionally, the hunk range can be followed by the heading of the section or function that the hunk is part of. This is mainly useful to make the diff easier to read. When creating a diff with GNU diff, the heading is identified by [[regular expression]] matching.<ref>[https://www.gnu.org/software/diffutils/manual/html_node/Sections.html 2.2.3 Showing Which Sections Differences Are in], GNU diffutils manual</ref> If a line is modified, it is represented as a deletion and addition. Since the hunks of the original and new file appear in the same hunk, such changes would appear adjacent to one another.<ref>[http://www.artima.com/weblogs/viewpost.jsp?thread=164293 Unified Diff Format] by [[Guido van Rossum]], June 14, 2006</ref> An occurrence of this in the example below is: <pre> -check this dokument. On +check this document. On </pre> The command <code>diff -u original new</code> produces the following output: <syntaxhighlight lang="diff"> --- /path/to/original timestamp +++ /path/to/new timestamp @@ -1,3 +1,9 @@ +This is an important +notice! It should +therefore be located at +the beginning of this +document! + This part of the document has stayed the same from version to @@ -8,13 +14,8 @@ compress the size of the changes. -This paragraph contains -text that is outdated. -It will be deleted in the -near future. - It is important to spell -check this dokument. On +check this document. On the other hand, a misspelled word isn't the end of the world. @@ -22,3 +23,7 @@ this paragraph needs to be changed. Things can be added after it. + +This paragraph contains +important new additions +to this document. </syntaxhighlight> '''Note''': ''Here, the diff output is shown with colors to make it easier to read. The diff utility does not produce colored output; its output is [[plain text]]. However, many tools can show the output with colors by using [[syntax highlighting]].'' Note that to successfully separate the file names from the timestamps, the delimiter between them is a tab character. This is invisible on screen and can be lost when diffs are copy/pasted from console/terminal screens.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)