# Diff

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Diff
> Markdown URL: https://mediated.wiki/source/Diff.md
> Source: https://en.wikipedia.org/wiki/Diff
> Source revision: 1356058322
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

Shell command for comparing file content

This article is about the command with Unix heritage. For the general topic of file comparison, see [File comparison](/source/File_comparison). For diffs in Wikipedia, see [Help:Diff](https://en.wikipedia.org/wiki/Help:Diff). For other uses, see [DIFF](/source/DIFF_(disambiguation)).

diff Original authors Douglas McIlroy (AT&T Bell Laboratories) Developers Various open-source and commercial developers Release June 1974; 52 years ago (1974-06) Written in C Operating system Unix, Unix-like, V, Plan 9, Inferno Platform Cross-platform Type Command License Plan 9: MIT License

**diff** is a [shell](/source/Shell_(computing)) [command](/source/Command_(computing)) that [compares](/source/Data_comparison) the content of files and reports differences. The term *diff* is also used to identify the output of the command and is [used as a verb](/source/Verbed) for running the command. To diff files, one runs diff to create a diff.[1]

Typically, the command is used to compare [text files](/source/Text_file), but it does support comparing [binary files](/source/Binary_file). If one of the input files contains non-textual data, then the command defaults to brief-mode in which it reports only a summary indication of whether the files differ. With the --text option, it always reports line-based differences, but the output may be difficult to understand since binary data is generally not structured in lines like text is.[2]

Although the command is primarily used ad hoc to analyze changes between two files, a special use is for creating a [patch file](/source/Patch_(computing)) for use with the [patch](/source/Patch_(Unix)) command – which was specifically designed to use a diff output report as a patch file. [POSIX](/source/POSIX) standardized the diff and patch commands including their shared file format.[3]

## History

The original diff [utility](/source/Utility_software) was developed in the early 1970s for the Unix operating system, at [Bell Labs](/source/Bell_Labs) in Murray Hill, New Jersey. It was part of the 5th Edition of Unix released in 1974,[4] and was written by [Douglas McIlroy](/source/Douglas_McIlroy), and [James Hunt](/source/James_W._Hunt). This research was published in a 1976 paper co-written with James W. Hunt, who developed an initial prototype of diff.[5] The algorithm this paper described became known as the [Hunt–Szymanski algorithm](/source/Hunt%E2%80%93Szymanski_algorithm).

McIlroy's work was preceded and influenced by [Steve Johnson](/source/Stephen_C._Johnson)'s comparison program on [GECOS](/source/GECOS) and [Mike Lesk](/source/Mike_Lesk)'s proof program. Proof also originated on Unix and, like diff, produced line-by-line changes and even used angle-brackets (">" and "<") for presenting line insertions and deletions in the program's output. The [heuristics](/source/Heuristic) used in these early applications were, however, deemed unreliable. The potential usefulness of a diff tool provoked McIlroy into researching and designing a more robust tool that could be used in a variety of tasks, but perform well in the processing and size limitations of the [PDP-11](/source/PDP-11)'s hardware. His approach to the problem resulted from collaboration with individuals at Bell Labs including [Alfred Aho](/source/Alfred_Aho), Elliot Pinson, [Jeffrey Ullman](/source/Jeffrey_Ullman), and Harold S. Stone.

In the context of Unix, the use of the [ed](/source/Ed_(Unix)) line editor provided diff with the natural ability to create machine-usable "edit scripts". These edit scripts, when saved to a file, can, along with the original file, be reconstituted by ed into the modified file in its entirety. This greatly reduced the [secondary storage](/source/Secondary_storage) necessary to maintain multiple versions of a file. McIlroy considered writing a post-processor for diff where a variety of output formats could be designed and implemented, but he found it more frugal and simpler to have diff be responsible for generating the syntax and reverse-order input accepted by the ed command.

In 1984, [Larry Wall](/source/Larry_Wall) created the [patch](/source/Patch_(Unix)) utility (releasing its source code on the *mod.sources* and *net.sources* newsgroups[6][7][8]) for patching text files, using the output from diff plus the diff input file with the content before changes to create a file with the content after changes.

[X/Open](/source/X%2FOpen) Portability Guide issue 2 of 1987 includes diff. Context mode was added in POSIX.1-2001 (issue 6). Unified mode was added in POSIX.1-2008 (issue 7).[9]

In diff's early years, common uses included comparing changes in the source of software code and markup for technical documents, verifying program debugging output, comparing filesystem listings and analyzing computer assembly code. The output targeted for ed was motivated to provide compression for a sequence of modifications made to a file.[*[citation needed](https://en.wikipedia.org/wiki/Wikipedia:Citation_needed)*] The [Source Code Control System](/source/Source_Code_Control_System) (SCCS) and its ability to archive revisions emerged in the late 1970s as a consequence of storing edit scripts from diff.

## Algorithm

Unlike [edit distance](/source/Edit_distance) notions used for other purposes, diff is line-oriented rather than character-oriented, but it is like [Levenshtein distance](/source/Levenshtein_distance) in that it tries to determine the smallest set of deletions and insertions to create one file from the other.

The operation of diff is based on solving the [longest common subsequence problem](/source/Longest_common_subsequence_problem).[5] In this problem, given two sequences of items:

a b c d f g h j q z

a b c d e f g i j k r x y z

and we want to find a longest sequence of items that is present in both original sequences in the same order. That is, we want to find a new sequence which can be obtained from the first original sequence by deleting some items, and from the second original sequence by deleting other items. We also want this sequence to be as long as possible. In this case it is

a b c d  f  g  j  z

From a longest common subsequence it is only a small step to get diff-like output: if an item is absent in the subsequence but present in the first original sequence, it must have been deleted (as indicated by the '-' marks, below). If it is absent in the subsequence but present in the second original sequence, it must have been inserted (as indicated by the '+' marks).

e   h i   q   k r x y
+   - +   -   + + + +

## Use

The diff command accepts two arguments like: diff *original* *new*. Commonly, the arguments each identify normal files, but if the two arguments identify directories, then the command compares corresponding files in the directories. With the -r option, it recursively descends matching subdirectories to compare files with corresponding relative paths.

### Default output format

The example below shows the original and new file content as well as the resulting diff output in the default format. The output is shown with coloring to improve readability. By default, diff outputs [plain text](/source/Plain_text), but GNU diff does use color [highlighting](/source/Syntax_highlighting) when the --color option is used.[*[citation needed](https://en.wikipedia.org/wiki/Wikipedia:Citation_needed)*]

original: This part of the document has stayed the same from version to version. It shouldn't be shown if it doesn't change. Otherwise, that would not be helping to 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 the other hand, a misspelled word isn't the end of the world. Nothing in the rest of this paragraph needs to be changed. Things can be added after it. new: 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 version. It shouldn't be shown if it doesn't change. Otherwise, that would not be helping to compress the size of the changes. It is important to spell check this document. On the other hand, a misspelled word isn't the end of the world. Nothing in the rest of this paragraph needs to be changed. Things can be added after it. This paragraph contains important new additions to this document. output: 0a1,6 > This is an important > notice! It should > therefore be located at > the beginning of this > document! > 11,15d16 < This paragraph contains < text that is outdated. < It will be deleted in the < near future. < 17c18 < check this dokument. On --- > check this document. On 24a26,29 > > This paragraph contains > important new additions > to this document.

In this default format, a stands for added, d for deleted and c for changed. The line number of the original file appears before the single-letter code and the line number of the new file appears after. The [less-than](/source/Less-than_sign) and [greater-than](/source/Greater-than_sign) signs (at the beginning of lines that are added, deleted or changed) indicate which file the lines appear in. Addition lines are added to the original file to appear in the new file. Deletion lines are deleted from the original file to be missing in the new file.

By default, lines common to both files are not shown. Lines that have moved are shown as added at their new location and as deleted from their old location.[10] However, some diff tools highlight moved lines.

### Edit script

An [ed](/source/Ed_(text_editor)) script can be generated by modern versions of diff with the -e option. The resulting edit script for this example is as follows:

24**a**

*This paragraph contains*
*important new additions*
*to this document.*
.
17**c**
*check this document. On*
.
11,15**d**
0**a**
*This is an important*
*notice! It should*
*therefore be located at*
*the beginning of this*
*document!*

.

In order to transform the content of the original file into the content of new file using ed, one appends two lines to this diff file, one line containing a w (write) command, and one containing a q (quit) command (e.g. by printf "w\nq\n" >> mydiff). Here we gave the diff file the name *mydiff* and the transformation will then happen when we run ed -s original < mydiff.

### Context format

The [Berkeley distribution of Unix](/source/BSD) made a point of adding the *context format* (-c) and the ability to recurse on filesystem directory structures (-r), adding those features in 2.8 BSD, released in July 1981. The context format of diff introduced at Berkeley helped with distributing patches for source code that may have been changed minimally.

In the context format, any changed lines are shown alongside unchanged lines before and after. The inclusion of any number of unchanged lines provides a *context* to the patch. The *context* consists of lines that have not changed between the two files and serve as a reference to locate the lines' place in a modified file and find the intended location for a change to be applied regardless of whether the line numbers still correspond. The context format introduces greater readability for humans and reliability when applying the patch, and an output which is accepted as input to the [patch](/source/Patch_(Unix)) program. This intelligent behavior is not possible with the traditional diff output.

The number of unchanged lines shown above and below a change *hunk* can be defined by the user, even zero, but three lines is typically the default. If the context of unchanged lines in a hunk overlap with an adjacent hunk, then diff will avoid duplicating the unchanged lines and merge the hunks into a single hunk.

A "!" represents a change between lines that correspond in the two files, whereas a "+" represents the addition of a line, and a "-" the removal of a line. A blank [space](/source/Space_(punctuation)) represents an unchanged line. At the beginning of the patch is the file information, including the full path and a [time stamp](/source/Time_stamp) delimited by a tab character. At the beginning of each hunk are the line numbers that apply for the corresponding change in the files. A number range appearing between sets of three asterisks applies to the original file, while sets of three dashes apply to the new file. The hunk ranges specify the starting and ending line numbers in the respective file.

The command diff -c original new produces the following output:

*** /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,20 ****
  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
  the other hand, a
  misspelled word isn't
  the end of the world.
--- 14,21 ----
  compress the size of the
  changes.

  It is important to spell
! check this document. On
  the other hand, a
  misspelled word isn't
  the end of the world.
***************
*** 22,24 ****
--- 23,29 ----
  this paragraph needs to
  be changed. Things can
  be added after it.
+
+ This paragraph contains
+ important new additions
+ to this document.

### Unified format

The *unified format* (or *unidiff*)[11][12] 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](/source/Command-line_option). This output is often used as input to the [patch](/source/Patch_(Unix)) 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](/source/Richard_Stallman) added unified diff support to the [GNU Project](/source/GNU)'s diff 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](/source/Header_(computing)) 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](/source/Plus_sign), and deletion lines are preceded by a [minus sign](/source/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 signs](/source/At_sign), and combines onto a single line what appears on two lines in the context format ([above](#Context_format)). The format of the range information line is as follows:

@@ -l,s +l,s @@ *optional section heading*

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](/source/Regular_expression) matching.[13]

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.[14] An occurrence of this in the example below is:

-check this dokument. On
+check this document. On

The command diff -u original new produces the following output:

--- /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.

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.

### Extensions

There are some modifications and extensions to the diff formats that are used and understood by certain programs and in certain contexts. For example, some [revision control](/source/Revision_control) systems—such as [Subversion](/source/Subversion_(software))—specify a version number, "working copy", or any other comment instead of or in addition to a timestamp in the diff's header section.

Some tools allow diffs for several different files to be merged into one, using a header for each modified file that may look something like this:

Index: path/to/file.cpp

The special case of files that do not end in a newline is not handled. Neither unidiff nor the POSIX diff standard define a way to handle this type of files. (Indeed, such files are not "text" files by strict POSIX definitions.[15]) GNU diff and git produce "\ No newline at end of file" (or a translated version) as a diagnostic, but this behavior is not portable.[16] GNU patch does not seem to handle this case, while git-apply does.[17]

The [patch](/source/Patch_(Unix)) program does not necessarily recognize implementation-specific diff output. GNU patch is, however, known to recognize git patches and act a little differently.[18]

## Implementations and related programs

Changes since 1975 include improvements to the core algorithm, the addition of useful features to the command, and the design of new output formats. The basic algorithm is described in the papers *An O(ND) Difference Algorithm and its Variations* by [Eugene W. Myers](/source/Eugene_Myers)[19] and in *A File Comparison Program* by Webb Miller and Myers.[20] The algorithm was independently discovered and described in *Algorithms for Approximate String Matching*, by [Esko Ukkonen](/source/Esko_Ukkonen).[21] The first editions of the diff program were designed for line comparisons of text files expecting the [newline](/source/Newline) character to delimit lines. By the 1980s, support for binary files resulted in a shift in the application's design and implementation.

GNU diff and diff3 are included in the **diffutils** package with other diff and [patch](/source/Patch_(Unix)) related utilities.[22]

### Formatters and front-ends

Postprocessors **sdiff** and **diffmk** render side-by-side diff listings and applied change marks to printed documents, respectively. Both were developed elsewhere in Bell Labs in or before 1981.[*[citation needed](https://en.wikipedia.org/wiki/Wikipedia:Citation_needed)*][*[discuss](https://en.wikipedia.org/wiki/Talk:Diff#topicality_of_front-ends)*]

[Diff3](/source/Diff3) compares one file against two other files by reconciling two diffs. It was originally conceived by Paul Jensen to reconcile changes made by two people editing a common source. It is also used by revision control systems, e.g. [RCS](/source/Revision_Control_System), for [merging](/source/Merge_(revision_control)).[23]

[Emacs](/source/Emacs) has [Ediff](/source/Ediff) for showing the changes a patch would provide in a user interface that combines interactive editing and merging capabilities for patch files.

[Vim](/source/Vim_(text_editor)) provides **vimdiff** to compare from two to eight files, with differences highlighted in color.[24] While historically invoking the diff program, modern vim uses [git](/source/Git)'s fork of xdiff library (LibXDiff) code, providing improved speed and functionality.[25]

GNU [Wdiff](https://en.wikipedia.org/w/index.php?title=Wdiff&action=edit&redlink=1)[26] is a front end to diff that shows the words or phrases that changed in a text document of written language even in the presence of word-wrapping or different column widths.

colordiff is a Perl wrapper for 'diff' and produces the same output but with colorization for added and deleted bits.[27] diff-so-fancy and diff-highlight are newer analogues.[28] "delta" is a Rust rewrite that highlights changes and the underlying code at the same time.[29]

**Patchutils** contains tools that combine, rearrange, compare and fix context diffs and unified diffs.[30]

### Algorithmic derivatives

Utilities that compare source files by their syntactic structure have been built mostly as research tools for some programming languages;[31][32][33] some are available as commercial tools.[34][35] In addition, free tools that perform syntax-aware diff include:

- C++: zograscope, AST-based.[36]

- HTML: Daisydiff,[37] html-differ.

- XML: *xmldiffpatch* by Microsoft and *xmldiffmerge* for IBM.[38][39]

- [JavaScript](/source/JavaScript): astii (AST-based).

- Multi-language: [Pretty Diff](/source/Pretty_Diff) (format code and then diff)[40]

**spiff** is a variant of *diff* that ignores differences in floating point calculations with roundoff errors and [whitespace](/source/Space_(punctuation)), both of which are generally irrelevant to source code comparison. [Bellcore](/source/Telcordia_Technologies) wrote the original version.[41][42] An [HPUX](/source/HPUX) port is the most current public release. spiff does not support binary files. spiff outputs to the [standard output](/source/Standard_output) in standard diff format and accepts inputs in the [C](/source/C_(programming_language)), [Bourne shell](/source/Bourne_shell), [Fortran](/source/Fortran), [Modula-2](/source/Modula-2) and [Lisp](/source/Lisp_(programming_language)) [programming languages](/source/Programming_language).[43][44][41][45][42]

LibXDiff is an LGPL [library](/source/Library_(computing)) that provides an interface to many algorithms from 1998. An improved Myers algorithm with [Rabin fingerprint](/source/Rabin_fingerprint) was originally implemented (as of the final release of 2008),[46] but [git](/source/Git) and [libgit2](/source/Libgit2)'s fork has since expanded the repository with many of its own. One algorithm called "histogram" is generally regarded as much better than the original Myers algorithm, both in speed and quality.[47][48] This is the modern version of *LibXDiff* used by Vim.[25]

## See also

- [cmp](/source/Cmp_(Unix)) – File comparison command

- [Comparison of file comparison tools](/source/Comparison_of_file_comparison_tools)

- [Delta encoding](/source/Delta_encoding) – Type of data transmission method

- [Difference operator](/source/Difference_operator) – Pattern defining an infinite sequence of numbersPages displaying short descriptions of redirect targets

- [File Compare](/source/File_Compare) – Command-line program that compares multiple files

- [History of software configuration management](/source/History_of_software_configuration_management)

- [Revision control](/source/Revision_control) – Managing versions of source code or dataPages displaying short descriptions of redirect targets

- [Software configuration management](/source/Software_configuration_management) – Tracking and controlling software changes

- [WinDiff](/source/WinDiff) – File comparison program by Microsoft

- [Ramseyer Rule](/source/Ramseyer_Rule) - standard format for amending legal text

## References

1. **[^](#cite_ref-1)** Eric S. Raymond (ed.), ["diff"](http://catb.org/jargon/html/D/diff.html) [Archived](https://web.archive.org/web/20140131071625/http://www.catb.org/jargon/html/D/diff.html) 2014-01-31 at the [Wayback Machine](/source/Wayback_Machine), *The Jargon File*, version 4.4.7

1. **[^](#cite_ref-2)** MacKenzie *et al.* "Binary Files and Forcing Text Comparison" in *Comparing and Merging Files with GNU Diff and Patch*. Downloaded 28 April 2007. [\[1\]](https://www.gnu.org/software/diffutils/manual/html_node/Binary.html) [Archived](https://web.archive.org/web/20171219223414/http://www.gnu.org/software/diffutils/manual/html_node/Binary.html) 2017-12-19 at the [Wayback Machine](/source/Wayback_Machine)

1. **[^](#cite_ref-3)** [IEEE Computer Society](/source/IEEE_Computer_Society); [The Open Group](/source/The_Open_Group) (26 September 2008). *Standard for Information Technology—Portable Operating System Interface (POSIX) Base Specifications, Issue 7*. pp. 2599–2607. IEEE Std. 1003.1-2001 specifies traditional, "ed script", and context diff output formats; IEEE Std. 1003.1-2008 added the (by then more common) unified format.

1. **[^](#cite_ref-4)** ["diff - differential file comparison"](https://minnie.tuhs.org/cgi-bin/utree.pl?file=V5/usr/source/s1/diff1.c). *minnie.tuhs.org*. Retrieved 2026-03-25.

1. ^ [***a***](#cite_ref-diff_paper_5-0) [***b***](#cite_ref-diff_paper_5-1) James W. Hunt; M. Douglas McIlroy (June 1976). ["An Algorithm for Differential File Comparison"](http://www.cs.dartmouth.edu/~doug/diff.pdf) (PDF). *Computing Science Technical Report, Bell Laboratories*. **41**. [Archived](https://web.archive.org/web/20141226005228/http://www.cs.dartmouth.edu/~doug/diff.pdf) (PDF) from the original on 2014-12-26. Retrieved 2015-05-06.

1. **[^](#cite_ref-6)** Larry Wall (November 9, 1984). ["A patch applier--YOU WANT THIS!!!"](https://groups.google.com/d/msg/net.sources/qtfVio1sSHs/G0cPT5HFDFcJ). [Newsgroup](/source/Usenet_newsgroup): [net.sources](news:net.sources). [Usenet:](/source/Usenet_(identifier)) [1457@sdcrdcf.UUCP](news:1457@sdcrdcf.UUCP). [Archived](https://web.archive.org/web/20220219233604/https://groups.google.com/g/net.sources/c/qtfVio1sSHs/m/G0cPT5HFDFcJ) from the original on February 19, 2022. Retrieved May 11, 2015.

1. **[^](#cite_ref-7)** Larry Wall (November 29, 1984). ["patch version 1.2--YOU WANT THIS"](https://groups.google.com/d/msg/net.sources/uWFr9NOp_fw/SRS_P2vSgFgJ). [Newsgroup](/source/Usenet_newsgroup): [net.sources](news:net.sources). [Usenet:](/source/Usenet_(identifier)) [1508@sdcrdcf.UUCP](news:1508@sdcrdcf.UUCP). [Archived](https://web.archive.org/web/20200321140052/https://groups.google.com/forum/) from the original on March 21, 2020. Retrieved May 11, 2015.

1. **[^](#cite_ref-8)** Larry Wall (May 8, 1985). ["patch version 1.3"](https://groups.google.com/d/msg/mod.sources/xSQM63e39YY/apNNJSkJi0gJ). [Newsgroup](/source/Usenet_newsgroup): [net.sources](news:net.sources). [Usenet:](/source/Usenet_(identifier)) [813@genrad.UUCP](news:813@genrad.UUCP). [Archived](https://web.archive.org/web/20220219233604/https://groups.google.com/g/mod.sources/c/xSQM63e39YY/m/apNNJSkJi0gJ) from the original on February 19, 2022. Retrieved May 11, 2015.

1. **[^](#cite_ref-9)** [diff](https://pubs.opengroup.org/onlinepubs/9799919799/utilities/diff.html) – Shell and Utilities Reference, [The Single UNIX Specification](/source/Single_Unix_Specification), Version 5 from [The Open Group](/source/The_Open_Group)

1. **[^](#cite_ref-10)** David MacKenzie; Paul Eggert; Richard Stallman (1997). [*Comparing and Merging Files with GNU Diff and Patch*](https://www.gnu.org/software/diffutils/manual/). Bristol: Network Theory. [ISBN](/source/ISBN_(identifier)) [978-0-9541617-5-0](https://en.wikipedia.org/wiki/Special:BookSources/978-0-9541617-5-0). [Archived](https://web.archive.org/web/20150331031946/http://www.gnu.org/software/diffutils/manual/) from the original on 2015-03-31. Retrieved 2015-03-17.

1. **[^](#cite_ref-11)** ["Detailed Description of Unified Format"](https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html). *GNU Diffutils (version 3.7, 7 January 2018)*. [Archived](https://web.archive.org/web/20200118142136/http://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html) from the original on 18 January 2020. Retrieved 29 January 2020.

1. **[^](#cite_ref-12)** van Rossum, Guido. ["Unified Diff Format"](https://www.artima.com/weblogs/viewpost.jsp?thread=164293). *All Things Pythonic*. [Archived](https://web.archive.org/web/20191225234517/https://www.artima.com/weblogs/viewpost.jsp?thread=164293) from the original on 2019-12-25. Retrieved 2020-01-29.

1. **[^](#cite_ref-13)** [2.2.3 Showing Which Sections Differences Are in](https://www.gnu.org/software/diffutils/manual/html_node/Sections.html), GNU diffutils manual

1. **[^](#cite_ref-14)** [Unified Diff Format](http://www.artima.com/weblogs/viewpost.jsp?thread=164293) by [Guido van Rossum](/source/Guido_van_Rossum), June 14, 2006

1. **[^](#cite_ref-15)** [http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_403](http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_403) [Archived](https://web.archive.org/web/20130429195728/http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_403) 2013-04-29 at the [Wayback Machine](/source/Wayback_Machine) Section 3.206

1. **[^](#cite_ref-16)** ["Incomplete Lines (Comparing and Merging Files)"](https://www.gnu.org/software/diffutils/manual/html_node/Incomplete-Lines.html). *www.gnu.org*. [Archived](https://web.archive.org/web/20230508092618/https://www.gnu.org/software/diffutils/manual/html_node/Incomplete-Lines.html) from the original on 2023-05-08. Retrieved 2023-06-15.

1. **[^](#cite_ref-17)** ["git: apply.c"](https://github.com/git/git/blob/69c786637d7a7fe3b2b8f7d989af095f5f49c3a8/apply.c#LL2901C35-L2901C39). Git. 8 May 2023. [Archived](https://web.archive.org/web/20230513063349/https://github.com/git/git/blob/69c786637d7a7fe3b2b8f7d989af095f5f49c3a8/apply.c#LL2901C35-L2901C39) from the original on 13 May 2023. Retrieved 15 June 2023.

1. **[^](#cite_ref-18)** ["patch.c\src - patch.git - GNU patch"](https://git.savannah.gnu.org/cgit/patch.git/tree/src/patch.c?id=c835ecc67b7e37c0d0b7dd7e032209fdaa285808#n1919). *git.savannah.gnu.org*. [Archived](https://web.archive.org/web/20230508094116/https://git.savannah.gnu.org/cgit/patch.git/tree/src/patch.c?id=c835ecc67b7e37c0d0b7dd7e032209fdaa285808#n1919) from the original on 2023-05-08. Retrieved 2023-06-15. In git-style diffs, the "before" state of each patch refers to the initial state before modifying any files,..

1. **[^](#cite_ref-19)** E. Myers (1986). "An O(ND) Difference Algorithm and Its Variations". *Algorithmica*. **1** (2): 251–266. [CiteSeerX](/source/CiteSeerX_(identifier)) [10.1.1.4.6927](https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927). [doi](/source/Doi_(identifier)):[10.1007/BF01840446](https://doi.org/10.1007%2FBF01840446). [S2CID](/source/S2CID_(identifier)) [6996809](https://api.semanticscholar.org/CorpusID:6996809).

1. **[^](#cite_ref-20)** Webb Miller; Eugene W. Myers (1985). "A File Comparison Program". *Software: Practice and Experience*. **15** (11): 1025–1040. [CiteSeerX](/source/CiteSeerX_(identifier)) [10.1.1.189.70](https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.189.70). [doi](/source/Doi_(identifier)):[10.1002/spe.4380151102](https://doi.org/10.1002%2Fspe.4380151102). [S2CID](/source/S2CID_(identifier)) [15489614](https://api.semanticscholar.org/CorpusID:15489614).

1. **[^](#cite_ref-21)** Esko Ukkonen (1985). ["Algorithms for Approximate String Matching"](https://doi.org/10.1016%2FS0019-9958%2885%2980046-2). *Information and Control*. **64** (1–3): 100–118. [doi](/source/Doi_(identifier)):[10.1016/S0019-9958(85)80046-2](https://doi.org/10.1016%2FS0019-9958%2885%2980046-2).

1. **[^](#cite_ref-22)** [GNU Diff utilities](https://www.gnu.org/software/diffutils/) [Archived](https://web.archive.org/web/20150316032418/http://www.gnu.org/software/diffutils/) 2015-03-16 at the [Wayback Machine](/source/Wayback_Machine). Made available by the [Free Software Foundation](/source/Free_Software_Foundation). Free Documentation. Free source code.

1. **[^](#cite_ref-23)** ["merge (GNU RCS 5.10.0)"](https://www.gnu.org/software/rcs/manual/html_node/merge.html). *gnu.org*. [Archived](https://web.archive.org/web/20190918125803/http://www.gnu.org/software/rcs/manual/html_node/merge.html) from the original on 18 September 2019. Retrieved 22 January 2021.

1. **[^](#cite_ref-24)** [Moolenaar, Bram](/source/Bram_Moolenaar). ["Vim documentation: diff"](https://vimhelp.org/diff.txt.html#vimdiff). *vimdoc.sourceforge.net*. [Archived](https://web.archive.org/web/20200216203940/https://vimhelp.org/diff.txt.html#vimdiff) from the original on 16 February 2020. Retrieved 1 May 2020. The easiest way to start editing in diff mode is with the "vimdiff" command. This starts Vim as usual, and additionally sets up for viewing the differences between the arguments. vimdiff file1 file2 [file3] [file4] [...file8] This is equivalent to: vim -d file1 file2 [file3] [file4] [...file8]

1. ^ [***a***](#cite_ref-brabandt2018_25-0) [***b***](#cite_ref-brabandt2018_25-1) Brabandt, Christian (1 December 2018). ["The power of diff"](https://vimways.org/2018/the-power-of-diff/). *Vimways*. [Archived](https://web.archive.org/web/20181202020105/https://vimways.org/2018/the-power-of-diff/) from the original on 2 December 2018. Retrieved 1 May 2020.

1. **[^](#cite_ref-26)** ["gnu.org"](https://gnu.org/s/wdiff/). *gnu.org*. [Archived](https://web.archive.org/web/20200811124535/https://gnu.org/s/wdiff/) from the original on 2020-08-11. Retrieved 2020-09-12.

1. **[^](#cite_ref-27)** ["colordiff"](https://www.colordiff.org/). *www.colordiff.org*. [Archived](https://web.archive.org/web/20180614121429/https://www.colordiff.org/) from the original on 2018-06-14. Retrieved 2018-06-14.

1. **[^](#cite_ref-28)** ["diff-so-fancy"](https://github.com/so-fancy/diff-so-fancy). So Fancy. 6 May 2023. [Archived](https://web.archive.org/web/20230508093250/https://github.com/so-fancy/diff-so-fancy) from the original on 8 May 2023. Retrieved 8 May 2023.

1. **[^](#cite_ref-29)** Davison, Dan (8 May 2023). ["dandavison/delta"](https://github.com/dandavison/delta). *[GitHub](/source/GitHub)*. [Archived](https://web.archive.org/web/20230508093248/https://github.com/dandavison/delta) from the original on 8 May 2023. Retrieved 8 May 2023.

1. **[^](#cite_ref-30)** Waugh, Tim (12 June 2020). ["twaugh/patchutils"](https://github.com/twaugh/patchutils). *[GitHub](/source/GitHub)*. [Archived](https://web.archive.org/web/20201001234609/https://github.com/twaugh/patchutils) from the original on 1 October 2020. Retrieved 28 June 2020.

1. **[^](#cite_ref-31)** Horwitz, Susan (June 1990). ["Identifying the semantic and textual differences between two versions of a program"](http://www.cs.wisc.edu/wpis/papers/sigplan90.ps). *ACM SIGPLAN Notices*. **25** (6): 234–245. [CiteSeerX](/source/CiteSeerX_(identifier)) [10.1.1.49.3377](https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.49.3377). [doi](/source/Doi_(identifier)):[10.1145/93548.93574](https://doi.org/10.1145%2F93548.93574). [Archived](https://web.archive.org/web/20100612103752/http://www.cs.wisc.edu/wpis/papers/sigplan90.ps) from the original on 2010-06-12. Retrieved 2017-11-01.

1. **[^](#cite_ref-32)** Yang, Wuu (July 1991). "Identifying syntactic differences between two programs". *Software: Practice and Experience*. **21** (7): 739–755. [CiteSeerX](/source/CiteSeerX_(identifier)) [10.1.1.13.9377](https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.13.9377). [doi](/source/Doi_(identifier)):[10.1002/spe.4380210706](https://doi.org/10.1002%2Fspe.4380210706). [S2CID](/source/S2CID_(identifier)) [10853673](https://api.semanticscholar.org/CorpusID:10853673).

1. **[^](#cite_ref-33)** Grass. Cdiff: A syntax directed Diff for C++ programs. Proceedings USENIX C++ Conf., pp. 181-193, 1992

1. **[^](#cite_ref-34)** Compare++, [http://www.coodesoft.com/](http://www.coodesoft.com/) [Archived](https://web.archive.org/web/20111129033738/http://www.coodesoft.com/) 2011-11-29 at the [Wayback Machine](/source/Wayback_Machine)

1. **[^](#cite_ref-35)** SmartDifferencer, [http://www.semanticdesigns.com/Products/SmartDifferencer](http://www.semanticdesigns.com/Products/SmartDifferencer) [Archived](https://web.archive.org/web/20091014160445/http://www.semanticdesigns.com/Products/SmartDifferencer/) 2009-10-14 at the [Wayback Machine](/source/Wayback_Machine)

1. **[^](#cite_ref-36)** ["xaizek/zograscope"](https://github.com/xaizek/zograscope). *GitHub*. 26 May 2020. [Archived](https://web.archive.org/web/20201221105419/https://github.com/xaizek/zograscope) from the original on 21 December 2020. Retrieved 27 June 2020.

1. **[^](#cite_ref-37)** *DaisyDiff*, [https://code.google.com/p/daisydiff/](https://code.google.com/p/daisydiff/) [Archived](https://web.archive.org/web/20150319014218/http://code.google.com/p/daisydiff/) 2015-03-19 at the [Wayback Machine](/source/Wayback_Machine)

1. **[^](#cite_ref-38)** *xmldiffpatch*, [http://msdn.microsoft.com/en-us/library/aa302294.aspx](http://msdn.microsoft.com/en-us/library/aa302294.aspx) [Archived](https://web.archive.org/web/20091027123710/http://msdn.microsoft.com/en-us/library/aa302294.aspx) 2009-10-27 at the [Wayback Machine](/source/Wayback_Machine)

1. **[^](#cite_ref-39)** *xmldiffmerge*, [http://www.alphaworks.ibm.com/tech/xmldiffmerge](http://www.alphaworks.ibm.com/tech/xmldiffmerge) [Archived](https://web.archive.org/web/20090924034538/http://www.alphaworks.ibm.com/tech/xmldiffmerge) 2009-09-24 at the [Wayback Machine](/source/Wayback_Machine)

1. **[^](#cite_ref-40)** Cheney, Austin. *Pretty Diff - Documentation*. [http://prettydiff.com/documentation.php](http://prettydiff.com/documentation.php) [Archived](https://web.archive.org/web/20120731233435/http://prettydiff.com/documentation.php) 2012-07-31 at the [Wayback Machine](/source/Wayback_Machine)

1. ^ [***a***](#cite_ref-dontcallme_41-0) [***b***](#cite_ref-dontcallme_41-1) dontcallmedotcom. ["spiff"](https://github.com/dontcallmedom/spiff). *[GitHub](/source/GitHub)*. [Archived](https://web.archive.org/web/20150326181245/https://github.com/dontcallmedom/spiff) from the original on 2015-03-26. Retrieved 2013-06-16.

1. ^ [***a***](#cite_ref-hpux_42-0) [***b***](#cite_ref-hpux_42-1) Nachbar, Daniel W (1999-12-01). ["HP-UX Porting and Archiving"](http://hpux.connect.org.uk/hppd/hpux/Text/spiff-1.0/). UK. [Archived](https://web.archive.org/web/20120905154135/http://hpux.connect.org.uk/hppd/hpux/Text/spiff-1.0/) from the original on 2012-09-05. Retrieved 2013-06-13.

1. **[^](#cite_ref-43)** ["SPIFF 1"](http://www.math.utah.edu/cgi-bin/man2html.cgi?/usr/local/man/man1/spiff.1). 1988-02-02. [Archived](https://web.archive.org/web/20161002135508/http://www.math.utah.edu/cgi-bin/man2html.cgi?%2Fusr%2Flocal%2Fman%2Fman1%2Fspiff.1) from the original on 2016-10-02. Retrieved 2013-06-16.

1. **[^](#cite_ref-44)** Nachbar, Daniel W (1988-02-02). ["Man page"](http://hpux.connect.org.uk/hppd/hpux/Text/spiff-1.0/man.html). UK. [Archived](https://web.archive.org/web/20120910004102/http://hpux.connect.org.uk/hppd/hpux/Text/spiff-1.0/man.html) from the original on 2012-09-10. Retrieved 2013-06-16.

1. **[^](#cite_ref-45)** Davide (2009-09-28). ["stackoverflow"](https://stackoverflow.com/a/1489107/2291035). [Archived](https://web.archive.org/web/20220219233604/https://stackoverflow.com/questions/1428177/diff-tool-that-ignores-floating-point-formats-but-not-values-in-text/1489107) from the original on 2022-02-19. Retrieved 2013-06-16.

1. **[^](#cite_ref-46)** Libenzi, Davide. ["LibXDiff"](https://freshmeat.sourceforge.net/projects/xdiff-lib). *SourceForge FreshMeat*. [Archived](https://web.archive.org/web/20200701070301/http://freshmeat.sourceforge.net/projects/xdiff-lib) from the original on 2020-07-01. Retrieved 2020-06-28.

1. **[^](#cite_ref-47)** Nugroho, Yusuf Sulistyo; Hata, Hideaki; Matsumoto, Kenichi (January 2020). ["How different are different diff algorithms in Git?: Use --histogram for code changes"](https://doi.org/10.1007%2Fs10664-019-09772-z). *Empirical Software Engineering*: 790–823. [arXiv](/source/ArXiv_(identifier)):[1902.02467](https://arxiv.org/abs/1902.02467). [doi](/source/Doi_(identifier)):[10.1007/s10664-019-09772-z](https://doi.org/10.1007%2Fs10664-019-09772-z). [S2CID](/source/S2CID_(identifier)) [59608676](https://api.semanticscholar.org/CorpusID:59608676).

1. **[^](#cite_ref-48)** ["algorithm - What's the difference between 'git diff --patience' and 'git diff --histogram'?"](https://stackoverflow.com/a/32367597/). *Stack Overflow*. [Archived](https://web.archive.org/web/20220219233605/https://stackoverflow.com/questions/32365271/whats-the-difference-between-git-diff-patience-and-git-diff-histogram/32367597) from the original on 2022-02-19. Retrieved 2020-06-28. This does indeed show that histogram diff slightly beats Myers, while patience is much slower than the others.

## Further reading

- Paul Heckel (April 1978). ["A technique for isolating differences between files"](https://doi.org/10.1145%2F359460.359467). *Communications of the ACM*. **21** (4): 264–268. [doi](/source/Doi_(identifier)):[10.1145/359460.359467](https://doi.org/10.1145%2F359460.359467). [S2CID](/source/S2CID_(identifier)) [207683976](https://api.semanticscholar.org/CorpusID:207683976).[A technique for isolating differences between files](http://doi.acm.org/10.1145/359460.359467)

- A generic implementation of the Myers SES/LCS algorithm with the Hirschberg linear space refinement [(C source code)](http://www.ioplex.com/~miallen/libmba/dl/src/diff.c)

## External links

The Wikibook *[Guide to Unix](https://en.wikibooks.org/wiki/Guide_to_Unix)* has a page on the topic of: ***[Commands](https://en.wikibooks.org/wiki/Guide_to_Unix/Commands)***

- [diff](https://pubs.opengroup.org/onlinepubs/9799919799/utilities/diff.html): compare two files – Shell and Utilities Reference, [The Single UNIX Specification](/source/Single_Unix_Specification), Version 5 from [The Open Group](/source/The_Open_Group)

- [diff(1)](https://9p.io/magic/man2html/1/diff) – [Plan 9](/source/Plan_9_from_Bell_Labs) Programmer's Manual, Volume 1

- [diff(1)](http://man.cat-v.org/inferno/1/diff) – [Inferno](/source/Inferno_(operating_system)) General commands [Manual](/source/Man_page)

- [JavaScript Implementation](http://www.bodurov.com/JavaScriptDiff/) [Archived](https://web.archive.org/web/20180427003712/http://www.bodurov.com/JavaScriptDiff/)

v t e Unix command-line utilities and shell builtins File system cat chattr chmod chown chgrp cksum cmp cp dd du df file fuser ln ls mkdir mv pax pwd rm rmdir split tee touch type umask Processes at bg crontab fg kill nice ps time User environment env exit logname mesg talk tput uname who write Text processing awk basename comm csplit cut diff dirname ed ex fold head iconv join m4 more nl paste patch printf read sed sort strings tail tr troff uniq vi wc xargs Shell builtins alias cd echo test unset wait Searching find grep Documentation man Software development ar ctags lex make nm strip yacc Miscellaneous bc cal dc expr lp od sleep true and false Categories Standard Unix programs Unix SUS2008 utilities List

v t e Plan 9 command-line interface programs and shell builtins File system chmod chgrp cmp cp dd du file gzip ls mkdir pwd rm split tee touch Processes kill ps User environment passwd who Text processing awk basename comm diff ed eqn join sed sort spell strings tail tr troff uniq wc Shell builtins echo test Networking ip/ipconfig ip/ping netstat Searching grep Software development ar hoc lex nm strip yacc Miscellaneous bc cal fortune sleep Category

v t e Version control software Years, where available, indicate the date of first stable release. Systems with names in italics are no longer maintained or have planned end-of-life dates. Local only Free/open-source RCS (1982) SCCS (1973) Proprietary The Librarian (1969) Panvalet (1970s) PVCS (1985) QVCS (1991) Client–server Free/open-source CVS (1986, 1990 in C) CVSNT (1998) QVCS Enterprise (1998) Subversion (2000) Proprietary AccuRev SCM (2002) Azure DevOps Server (via TFVC) (2005) Services (via TFVC) (2014) ClearCase (1992) CMVC (1994) Dimensions CM (1980s) DSEE (1984) Integrity (2001) Perforce Helix (1995) SCLM (1980s?) Software Change Manager (1970s) StarTeam (1995) Surround SCM (2002) Synergy (1990) Team Concert (2008) Vault (2003) Visual SourceSafe (1994) Distributed Free/open-source BitKeeper (2000) Breezy (2017) Code Co-op (1997) Darcs (2002) DCVS (2002) Fossil (2007) Git (2005) GNU arch (2001) GNU Bazaar (2005) Mercurial (2005) Monotone (2003) Proprietary Azure DevOps Server (via Git) (2013) Services (via Git) (2014) TeamWare (1992) Plastic SCM (2006) Concepts Baseline Branch Trunk Changeset Commit Gated Delta compression Interleaved File comparison Fork Merge Monorepo Repository Tag Category Comparison List

---
Adapted from the Wikipedia article [Diff](https://en.wikipedia.org/wiki/Diff) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Diff?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
