xref: /freebsd/usr.bin/diff3/diff3.1 (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
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 June 23, 2022
33.Dt DIFF3 1
34.Os
35.Sh NAME
36.Nm diff3
37.Nd 3-way differential file comparison
38.Sh SYNOPSIS
39.Nm
40.Op Fl 3AaEeimTXx
41.Op Fl Fl diff-program Ar program
42.Op Fl Fl strip-trailing-cr
43.Op Fl L | Fl Fl label Ar label1
44.Op Fl L | Fl Fl label Ar label2
45.Op Fl L | Fl Fl label Ar label3
46.Ar file1 file2 file3
47.Nm
48.Op Fl Fl help
49.Op Fl Fl version
50.Sh DESCRIPTION
51The
52.Nm
53utility compares the contents of three different versions of a file,
54.Ar file1 ,
55.Ar file2
56and
57.Ar file3 ,
58writing the result to the standard output.
59The options describe different methods of merging and
60purging
61the separate versions into a new file.
62.Nm
63is used by
64.Xr rcs 1
65to merge specific versions or create
66new versions.
67.Pp
68The options are as follows:
69.Bl -tag -width "-E, -X"
70.It Fl 3 , Fl Fl easy-only
71Produces an output script suitable for
72.Xr ed 1
73with changes
74specific only to
75.Ar file3 .
76.It Fl A Fl Fl show-all
77Output all changes, bracketing conflicts.
78.It Fl a , Fl Fl text
79Treat all files as ASCII.
80.It Fl E , Fl Fl show-overlap
81.It Fl X
82Similar to
83.Fl e
84and
85.Fl x ,
86respectively, but treat overlapping changes (i.e., changes that would
87be noted with ==== in the normal listing) differently.
88The overlapping lines from both files will be inserted by the edit script,
89bracketed by "<<<<<<" and ">>>>>>" lines.
90.It Fl e , Fl Fl ed
91Produces output in a form suitable as an input script for the
92.Xr ed 1
93utility.
94The script may then be used to merge differences common between all
95three files and differences specific to
96.Ar file1
97and
98.Ar file3 .
99In other words, the
100.Fl e
101option ignores differences specific to
102.Ar file1
103and
104.Ar file2 ,
105and those specific to
106.Ar file2
107and
108.Ar file3 .
109It is useful for backing out changes specific to
110.Ar file2
111only.
112.It Fl Fl help
113Prints usage information and exits.
114.It Fl i
115Appends 'w' and 'q'
116.Xr ed 1
117commands.
118.It Fl L , Fl Fl label
119Defines labels to print instead of file names
120.Ar file1 ,
121.Ar file2
122and
123.Ar file3 .
124.It Fl m, Fl Fl merge
125Merge output instead of generating ed script.
126.It Fl T, Fl Fl initial-tab
127In the normal listing,
128use a tab instead of two spaces
129at the beginning of each line.
130In modes that produce an
131.Xr ed 1
132script, this option changes nothing.
133.It Fl x, Fl Fl overlap-only
134Produces an output script suitable for
135.Xr ed 1
136with changes
137specific only to all three versions.
138.It Fl Fl diff-program Ar program
139Use
140.Ar program
141instead of the default
142.Xr diff 1
143to compare files.
144.It Fl Fl strip-trailing-cr
145Strip trailing carriage return on input files.
146.It Fl Fl version
147Prints version information and exits.
148.El
149.Pp
150The
151.Fl E
152option is used by
153.Tn RCS
154.Xr merge 1
155to ensure that overlapping changes in the merged files are preserved
156and brought to someone's attention.
157.Pp
158For example, suppose lines 7-8 are changed in both
159.Ar file1
160and
161.Ar file2 .
162Applying the edit script generated by the command
163.Pp
164.Dl $ diff3 -E file1 file2 file3
165.Pp
166to
167.Ar file1
168results in the file:
169.Bd -literal -offset indent
170lines 1-6
171of file1
172<<<<<<< file1
173lines 7-8
174of file1
175=======
176lines 7-8
177of file3
178>>>>>>> file3
179rest of file1
180.Ed
181.Pp
182The default output of
183.Nm
184makes notation of the differences between all files, and those
185differences specific to each pair of files.
186The changes are described by the commands necessary for
187.Xr ed 1
188to create the desired target from the different versions.
189See
190.Xr diff 1
191for a description of the commands.
192.Bl -tag -width "====="
193.It Li \&====
194The lines beneath this notation are ranges of lines which are different
195between all files.
196.It \&==== Ns Va n
197The lines beneath this notation are ranges of lines which are exclusively
198different in file
199.Va n .
200.El
201.Sh SEE ALSO
202.Xr diff 1 ,
203.Xr ed 1 ,
204.Xr merge 1 ,
205.Xr rcs 1 ,
206.Xr sdiff 1
207.Sh HISTORY
208A
209.Nm
210command appeared in
211.At v7 .
212.Sh BUGS
213The
214.Fl e
215option cannot catch and change lines which have
216.Ql \&.
217as the first and only character on the line.
218The resulting script will fail on that line
219as
220.Ql \&.
221is an
222.Xr ed 1
223editing command.
224