Diff
DIFF or diff may refer to: * , a file comparison tool * Data comparison, methods and implementations to compare texts or files * Dubai International Film Festival * Dublin International Film Festival * Dharamshala International Film…
≈ 6 min read
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
DIFF or diff may refer to: * , a file comparison tool * Data comparison, methods and implementations to compare texts or files * Dubai International Film Festival * Dublin International Film Festival * Dharamshala International Film Festival * a motor vehicle's differential (mechanical device) * White blood cell differential, a medical test enumerating each type of white blood cell
diff is a shell command that compares 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 for running the command. To diff files, one runs diff to create a diff.
Typically, the command is used to compare text files, but it does support comparing binary files. If one of the input files contains non-textual data, the command defaults to brief-mode, reporting only a summary indication of whether the files differ.
With the option, it always reports line-based differences; however, the output may be difficult to understand, as binary data is generally not structured in lines like text. Although the command is primarily used ad hoc to analyze changes between two files, a special use is for creating a patch file for use with the patch command which was specifically designed to use a diff output report as a patch file.
POSIX standardized the and commands including their shared file format.
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. GNU diff can colorize output when the option is used; when no option is specified, color output is disabled by default. 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: In this default format, indicates added, indicates deleted, and indicates 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 and greater-than 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 and appear in the new file. Deletion lines are deleted from the original file and are 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. However, some diff tools highlight moved lines. /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. --- /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, a tab character serves as the delimiter.
This is invisible on screen and can be lost when diffs are copied and pasted from console/terminal screens.
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 and in A File Comparison Program by Webb Miller and Myers.
The algorithm was independently discovered and described in Algorithms for Approximate String Matching, by Esko Ukkonen. The first editions of the diff program were designed for line comparisons of text files, expecting the newline character to delimit lines. By the 1980s, support for binary files shifted the application's design and implementation.
GNU diff and diff3 are included in the diffutils package with other diff and patch related utilities.
See also
Ramseyer Rule - standard format for amending legal text
Further reading
A technique for isolating differences between files A generic implementation of the Myers SES/LCS algorithm with the Hirschberg linear space refinement (C source code)
External links
JavaScript Implementation Archived
Text derived from https://en.wikipedia.org/w/index.php?oldid=1167246483 under CC BY-SA 4.0; modifications have been made.