diff3
DeveloperAT&T Bell Laboratories
Initial releaseJanuary 1979; 47 years ago (1979-01)
Operating systemUnix and Unix-like
TypeCommand

diff3 is a Unix utility to compare three files and show any differences among them. diff3 can also merge files, implementing a three-way merge.

History and implementations

edit

diff3 originally appeared in Version 7 Unix of 1979. A very similar version was found in Berkeley Software Distribution (BSD) and was inherited into OpenBSD and probably Solaris.[1][2]

On most modern Unix-like systems, even BSD-derived ones like FreeBSD and NetBSD, the diff3 provided is GNU's version in diffutils (formerly GNU Tools). This version has the ability to merge files on its own without relying on ed. It internally invokes diff to do the comparison, but can use any other compatible tool too.[3]

The command is available as a separate package for Microsoft Windows as part of the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.[4]

"Diff3" has also become a generic name for the three-way-merge algorithm, specifically one based on reconciling two different diffs stemming from the first source.

Merging from a common ancestor

edit

When two people have made changes to copies of the same file, diff3 can produce a merged output that contains both sets of changes together with warnings about conflicts. diff3 can merge three or more sets of changes to a file by merging two change sets at a time.

diff3 can incorporate changes from two modified versions into a common preceding version. This enables users to merge the sets of changes represented by the two newer files. This can be enabled using a command like this: diff3 -m mine older yours.

This is like subtracting the file older from the file yours and adding the result to the file mine, or as merging into mine the changes that would turn older into yours. This merging is well-defined as long as mine and older match in the neighborhood of each such change. This fails to be true when all three input files differ or when only older differs; this is a conflict. When all three input files differ, the conflict is an overlap.

diff3 has several methods to handle overlaps and conflicts. It can omit overlaps or conflicts, or select only overlaps, or mark conflicts with special <<<<<<< and >>>>>>> lines.

diff3 can output the merge results as an ed script that can be applied to the first file to yield the merged output. However, directly generating the merged output bypasses some problems with ed.

See also

edit

References

edit
  1. ^ diff3(1) – OpenBSD General Commands Manual
  2. ^ "diff3 - man pages section 1: User Commands". Solaris 11.3 documentation.
  3. ^ diff3(1) – Linux General Commands Manual from ManKier.com
  4. ^ "Native Win32 ports of some GNU utilities". unxutils.sourceforge.net.
edit

📚 Artikel Terkait di Wikipedia

Diff

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 related

Emerge

the Portage package management system Emerge, a frontend for the diff and diff3 commands for Emacs Emergence, a concept in philosophy, systems theory and

Ferrari 488

The car also incorporates a Side-slip Angle Control system having an E-Diff3, F-Trac and magnetorheological suspension to improve handling at high speeds

UnxUtils

chgrp chmod chown cksum cmp comm compress cp csplit cut date dc dd df diff diff3 dircolors dirname du echo egrep env expand expr factor fgrep find flex fmt

Merge (version control)

the user to resolve. Three-way merging is implemented by the ubiquitous diff3 program, and was the central innovation that allowed the switch from file-locking

Research Unix

augmenting Dennis Ritchie's C compiler. Adds adb, at, awk, banner, basename, cu, diff3, expr, f77, factor, fortune, iostat, join, lex, lint, look, m4, make, rev

Comparison of file comparison tools

Coode Software No; Proprietary No 2010 2016-7-17 (3.0.1.0b) Yes No No diff, diff3 AT&T Yes; BSD 3-clause, BSD 4-clause, CDDL, GPL, Proprietary Yes 1974 No

List of GNU packages

15  2024-01-14 diffutils contains utilities to compare files diff, cmp, diff3, sdiff 3.12  2025-04-08 findutils contains search utilities find, locate