xref: /freebsd/usr.bin/diff3/diff3.1 (revision 732a02b4e77866604a120a275c082bb6221bd2ff)
1.\" $OpenBSD: diff3.1,v 1.7 2007/05/31 19:20:09 jmc Exp $
2.\"
3.\" Copyright (c) 1990, 1993, 1994
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"     @(#)diff3.1	8.2 (Berkeley) 4/18/94
31.\" $FreeBSD$
32.\"
33.Dd May 25, 2017
34.Dt DIFF3 1
35.Os
36.Sh NAME
37.Nm diff3
38.Nd 3-way differential file comparison
39.Sh SYNOPSIS
40.Nm diff3
41.Op Fl 3aEeXx
42.Ar file1 file2 file3
43.Sh DESCRIPTION
44The
45.Nm
46utility compares the contents of three different versions of a file,
47.Ar file1 ,
48.Ar file2
49and
50.Ar file3 ,
51writing the result to the standard output.
52The options describe different methods of merging and
53purging
54the separate versions into a new file.
55.Nm
56is used by
57.Xr rcs 1
58to merge specific versions or create
59new versions.
60.Pp
61The options are as follows:
62.Bl -tag -width "-E, -X"
63.It Fl 3
64Produces an output script suitable for
65.Xr ed 1
66with changes
67specific only to
68.Ar file3 .
69.It Fl a
70Treat all files as ASCII.
71.It Fl E , X
72Similar to
73.Fl e
74and
75.Fl x ,
76respectively, but treat overlapping changes (i.e., changes that would
77be noted with ==== in the normal listing) differently.
78The overlapping lines from both files will be inserted by the edit script,
79bracketed by "<<<<<<" and ">>>>>>" lines.
80.It Fl e
81Produces output in a form suitable as an input script for the
82.Xr ed 1
83utility.
84The script may then be used to merge differences common between all
85three files and differences specific to
86.Ar file1
87and
88.Ar file3 .
89In other words, the
90.Fl e
91option ignores differences specific to
92.Ar file1
93and
94.Ar file2 ,
95and those specific to
96.Ar file2
97and
98.Ar file3 .
99It is useful for backing out changes specific to
100.Ar file2
101only.
102.It Fl x
103Produces an output script suitable for
104.Xr ed 1
105with changes
106specific only to all three versions.
107.El
108.Pp
109The
110.Fl E
111option is used by
112.Tn RCS
113.Xr merge 1
114to ensure that overlapping changes in the merged files are preserved
115and brought to someone's attention.
116.Pp
117For example, suppose lines 7-8 are changed in both
118.Ar file1
119and
120.Ar file2 .
121Applying the edit script generated by the command
122.Pp
123.Dl $ diff3 -E file1 file2 file3
124.Pp
125to
126.Ar file1
127results in the file:
128.Bd -literal -offset indent
129lines 1-6
130of file1
131<<<<<<< file1
132lines 7-8
133of file1
134=======
135lines 7-8
136of file3
137>>>>>>> file3
138rest of file1
139.Ed
140.Pp
141The default output of
142.Nm
143makes notation of the differences between all files, and those
144differences specific to each pair of files.
145The changes are described by the commands necessary for
146.Xr ed 1
147to create the desired target from the different versions.
148See
149.Xr diff 1
150for a description of the commands.
151.Bl -tag -width "====="
152.It Li \&====
153The lines beneath this notation are ranges of lines which are different
154between all files.
155.It \&==== Ns Va n
156The lines beneath this notation are ranges of lines which are exclusively
157different in file
158.Va n .
159.El
160.Sh SEE ALSO
161.Xr diff 1 ,
162.Xr ed 1 ,
163.Xr merge 1 ,
164.Xr rcs 1 ,
165.Xr sdiff 1
166.Sh HISTORY
167A
168.Nm
169command appeared in
170.At v7 .
171.Sh BUGS
172The
173.Fl e
174option cannot catch and change lines which have
175.Ql \&.
176as the first and only character on the line.
177The resulting script will fail on that line
178as
179.Ql \&.
180is an
181.Xr ed 1
182editing command.
183