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