Diff

The title of this article is incorrect because of technical limitations. The correct title is diff.

In computing, diff is a utility that outputs the difference between two text files.

Contents

Usage

The output of this program is also called a diff. It is invoked from the command line with the names of two files:

diff firstone.txt secondone.txt

The result might look like this:

0a1,3
> This is an important notice! It should
> therefore be located at the beginning of
> this document!
7,12d9
< This paragraph contains text that is
< outdated - it will be deprecated and
< deleted in the near future.
< This is an important notice! It should
< therefore be located at the beginning of
< this document!
14,15c11,14
< spell check this dokument. On the other
< hand, I could do with some shoarma.
---
> spell check this document. On the other
> hand, I could do with some shoarma.
> This paragraph contains important new
> additions to this document.

Note that in this normal diff output, a stands for added, d for deleted and c for changed. By default, lines common to both files are not shown. Lines that have moved will show up as added on their new location and as deleted on their old location.

In unified format, each line that occurs only in the first file is preceded by a minus sign, each line that occurs only in the second file is preceded by a plus sign, and common lines are preceded by a space.

Lines beginning with three plus signs indicate the number of lines in each hunk, the file names, and where in the files to find them. Diff output is often used as input to the patch program.

The first editions of the diff program were designed for line comparisons in text files. By the 1980s, support for binary files was necessary resulting in a shift in the application's design and implementation.

History

The diff program was developed in the early 1970s on the Unix operating system which was emerging from AT&T Bell Labs in Murray Hill, New Jersey. The final version incorporated into these early Unix systems was written completely by Douglas McIlroy. This research was published in a 1976 paper which he co-wrote with James W. Hunt who also wrote one of the initial prototypes of diff.

McIlroy's work was preceded and influenced by Steve Johnson's comparison program on GECOS and Mike Lesk's proof program. Proof originated on Unix and produced line-by-line changes like diff and even used angle-brackets (">" and "<") for presenting line insertions and deletions in the program's output. The heuristics used in these early applications were deemed unreliable though. 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 space limitations of the PDP-11's hardware. His approach resulted from collaboration also with individuals at Bell Labs including Alfred Aho, Elliot Pinson, Jeffrey Ullman, and Harold S. Stone.

In the context of Unix, the use of the ed 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 space 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 diff's early years, common uses included comparing changes in programming language source code, source to 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. The Source Code Control System (SCCS) emerged in the late 1970s as a direct consequence of this development.

A conceptual predecessor of diff includes Project Xanadu, a hypertext project established in 1960 that had envisioned a version tracking system necessary for its "transpointing windows" feature. As part of this feature, file differences were subsumed in the expansive term "transclusion", when a document has included in it parts of other documents or revisions.

In the digital realm of the humanities, computer comparison systems were understood to have been created for working on literary works published as large volumes.

Variations

Most all diff implementations remain outwardly unchanged since 1975. The modifications include improvements to the core algorithm, the addition of useful features to the command, and the design of new output formats.

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.

The Berkeley distribution of Unix made a point of adding the context format (-C) and the ability to recurse on filesystem directory structures (-r).

The context format of diff introduced at Berkeley helped with distributing patches for source code that may have been changed minimally.

Paul Jensen, faced with consolidating changes from two branches of a program's source code tree proposed diff3, which persists for most as a curiosity, but is still useful to those finding themselves in Jensen's situation.

The GNU Project's diff application includes the unified context format and is combined in a package with other diff and patch related utilities.

Related Proprietary Software

MS-DOS 3.30 and later and all versions of Microsoft Windows have an fc (File Compare) command. Whenever fc encounters a difference between the two files it is presented in the following format:

***** old.txt
deleted lines
***** NEW.TXT
inserted lines
*****

Note that fc capitalizes the filename of the second file.

Others avaiable on Microsoft Windows:

Mac OS X includes the graphical FileMerge program from Apple in the developer tools package. This program offers automatic file merging, but is most useful as a simple but powerful manual merge tool for text based files. FileMerge expects Unix style newlines. Others available for Macintosh:

Free Software Implementations

The GNU Project has an implementation of diff (and diff3) that is available from the GNU diffutils (http://www.gnu.org/software/diffutils/diffutils.html) package.

Several tools on various platforms use the GNU diffutils engine and provide a graphical display, and some combine editing and merging capabilities. The following are some of these free tools.

See also

References

  • Hunt, James W. and McIlroy, M. Douglas, "An Algorithm for Differential File Comparison," 41, Computing Science Technical Report, Bell Laboratories, June 1976. [1] (http://www.cs.dartmouth.edu/~doug/)
  • "Comparing and Merging Files with GNU Diff and Patch", by David MacKenzie, Paul Eggert, and Richard Stallman (ISBN 0954161750) [2] (http://www.gnu.org/software/diffutils/manual/)
  • E. Myers, "An O(ND) Difference Algorithm and Its Variations," Algorithmica 1, 2 (1986), 251-266. (Postscript) (http://www.cs.arizona.edu/people/gene/PAPERS/diff.ps)
  • 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

de:Diff

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools