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