xref: /openbsd/usr.bin/diff3/diff3.1 (revision 9490d37c)
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.\"
32.Dd $Mdocdate: May 31 2007 $
33.Dt DIFF3 1
34.Os
35.Sh NAME
36.Nm diff3
37.Nd 3-way differential file comparison
38.Sh SYNOPSIS
39.Nm diff3
40.Op Fl 3aEeXx
41.Ar file1 file2 file3
42.Sh DESCRIPTION
43The
44.Nm
45utility compares the contents of three different versions of a file,
46.Ar file1 ,
47.Ar file2
48and
49.Ar file3 ,
50writing the result to the standard output.
51The options describe different methods of merging and
52purging
53the separate versions into a new file.
54.Nm
55is used by
56.Xr rcs 1
57to merge specific versions or create
58new versions.
59.Pp
60The options are as follows:
61.Bl -tag -width "-E, -X"
62.It Fl 3
63Produces an output script suitable for
64.Xr ed 1
65with changes
66specific only to
67.Ar file3 .
68.It Fl a
69Treat all files as ASCII.
70.It Fl E , X
71Similar to
72.Fl e
73and
74.Fl x ,
75respectively, but treat overlapping changes (i.e., changes that would
76be noted with ==== in the normal listing) differently.
77The overlapping lines from both files will be inserted by the edit script,
78bracketed by "<<<<<<" and ">>>>>>" lines.
79.It Fl e
80Produces output in a form suitable as an input script for the
81.Xr ed 1
82utility.
83The script may then be used to merge differences common between all
84three files and differences specific to
85.Ar file1
86and
87.Ar file3 .
88In other words, the
89.Fl e
90option ignores differences specific to
91.Ar file1
92and
93.Ar file2 ,
94and those specific to
95.Ar file2
96and
97.Ar file3 .
98It is useful for backing out changes specific to
99.Ar file2
100only.
101.It Fl x
102Produces an output script suitable for
103.Xr ed 1
104with changes
105specific only to all three versions.
106.El
107.Pp
108The
109.Fl E
110option is used by
111.Tn RCS
112.Xr merge 1
113to ensure that overlapping changes in the merged files are preserved
114and brought to someone's attention.
115.Pp
116For example, suppose lines 7-8 are changed in both
117.Ar file1
118and
119.Ar file2 .
120Applying the edit script generated by the command
121.Pp
122.Dl $ diff3 -E file1 file2 file3
123.Pp
124to
125.Ar file1
126results in the file:
127.Bd -literal -offset indent
128lines 1-6
129of file1
130<<<<<<< file1
131lines 7-8
132of file1
133=======
134lines 7-8
135of file3
136>>>>>>> file3
137rest of file1
138.Ed
139.Pp
140The default output of
141.Nm
142makes notation of the differences between all files, and those
143differences specific to each pair of files.
144The changes are described by the commands necessary for
145.Xr ed 1
146to create the desired target from the different versions.
147See
148.Xr diff 1
149for a description of the commands.
150.Bl -tag -width "====="
151.It Li \&====
152The lines beneath this notation are ranges of lines which are different
153between all files.
154.It \&==== Ns Va n
155The lines beneath this notation are ranges of lines which are exclusively
156different in file
157.Va n .
158.El
159.Sh ENVIRONMENT
160.Bl -tag -width TMPDIR
161.It Ev TMPDIR
162If the environment variable
163.Ev TMPDIR
164exists,
165.Nm
166will use the directory specified by
167.Ev TMPDIR
168as the temporary directory.
169.El
170.Sh FILES
171.Bl -tag -width /usr/libexec/diff3prog -compact
172.It Pa /tmp/d3a.XXXXXXXXXX
173temporary file
174.It Pa /tmp/d3b.XXXXXXXXXX
175temporary file
176.It Pa /usr/libexec/diff3prog
177the actual executable
178.El
179.Sh SEE ALSO
180.Xr diff 1 ,
181.Xr ed 1 ,
182.Xr merge 1 ,
183.Xr rcs 1 ,
184.Xr sdiff 1
185.Sh HISTORY
186A
187.Nm
188command appeared in
189.At v7 .
190.Sh BUGS
191The
192.Fl e
193option cannot catch and change lines which have
194.Ql \&.
195as the first and only character on the line.
196The resulting script will fail on that line
197as
198.Ql \&.
199is an
200.Xr ed 1
201editing command.
202