| 1 | This is diff.info, produced by makeinfo version 4.2 from diff.texi.
|
|---|
| 2 |
|
|---|
| 3 | This manual is for GNU Diffutils (version 2.8.1, 5 April 2002), and
|
|---|
| 4 | documents the GNU `diff', `diff3', `sdiff', and `cmp' commands for
|
|---|
| 5 | showing the differences between files and the GNU `patch' command for
|
|---|
| 6 | using their output to update files.
|
|---|
| 7 |
|
|---|
| 8 | Copyright (C) 1992, 1993, 1994, 1998, 2001, 2002 Free Software
|
|---|
| 9 | Foundation, Inc.
|
|---|
| 10 |
|
|---|
| 11 | Permission is granted to copy, distribute and/or modify this
|
|---|
| 12 | document under the terms of the GNU Free Documentation License,
|
|---|
| 13 | Version 1.1 or any later version published by the Free Software
|
|---|
| 14 | Foundation; with no Invariant Sections, with the Front-Cover texts
|
|---|
| 15 | being "A GNU Manual," and with the Back-Cover Texts as in (a)
|
|---|
| 16 | below. A copy of the license is included in the section entitled
|
|---|
| 17 | "GNU Free Documentation License."
|
|---|
| 18 |
|
|---|
| 19 | (a) The FSF's Back-Cover Text is: "You have freedom to copy and
|
|---|
| 20 | modify this GNU Manual, like GNU software. Copies published by
|
|---|
| 21 | the Free Software Foundation raise funds for GNU development."
|
|---|
| 22 |
|
|---|
| 23 | INFO-DIR-SECTION Individual utilities
|
|---|
| 24 | START-INFO-DIR-ENTRY
|
|---|
| 25 | * cmp: (diff)Invoking cmp. Compare 2 files byte by byte.
|
|---|
| 26 | * diff: (diff)Invoking diff. Compare 2 files line by line.
|
|---|
| 27 | * diff3: (diff)Invoking diff3. Compare 3 files line by line.
|
|---|
| 28 | * patch: (diff)Invoking patch. Apply a patch to a file.
|
|---|
| 29 | * sdiff: (diff)Invoking sdiff. Merge 2 files side-by-side.
|
|---|
| 30 | END-INFO-DIR-ENTRY
|
|---|
| 31 |
|
|---|
| 32 | INFO-DIR-SECTION GNU packages
|
|---|
| 33 | START-INFO-DIR-ENTRY
|
|---|
| 34 | * Diff: (diff). Comparing and merging files.
|
|---|
| 35 | END-INFO-DIR-ENTRY
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 | File: diff.info, Node: Top, Next: Overview, Up: (dir)
|
|---|
| 39 |
|
|---|
| 40 | Comparing and Merging Files
|
|---|
| 41 | ***************************
|
|---|
| 42 |
|
|---|
| 43 | This manual is for GNU Diffutils (version 2.8.1, 5 April 2002), and
|
|---|
| 44 | documents the GNU `diff', `diff3', `sdiff', and `cmp' commands for
|
|---|
| 45 | showing the differences between files and the GNU `patch' command for
|
|---|
| 46 | using their output to update files.
|
|---|
| 47 |
|
|---|
| 48 | Copyright (C) 1992, 1993, 1994, 1998, 2001, 2002 Free Software
|
|---|
| 49 | Foundation, Inc.
|
|---|
| 50 |
|
|---|
| 51 | Permission is granted to copy, distribute and/or modify this
|
|---|
| 52 | document under the terms of the GNU Free Documentation License,
|
|---|
| 53 | Version 1.1 or any later version published by the Free Software
|
|---|
| 54 | Foundation; with no Invariant Sections, with the Front-Cover texts
|
|---|
| 55 | being "A GNU Manual," and with the Back-Cover Texts as in (a)
|
|---|
| 56 | below. A copy of the license is included in the section entitled
|
|---|
| 57 | "GNU Free Documentation License."
|
|---|
| 58 |
|
|---|
| 59 | (a) The FSF's Back-Cover Text is: "You have freedom to copy and
|
|---|
| 60 | modify this GNU Manual, like GNU software. Copies published by
|
|---|
| 61 | the Free Software Foundation raise funds for GNU development."
|
|---|
| 62 |
|
|---|
| 63 | * Menu:
|
|---|
| 64 |
|
|---|
| 65 | * Overview:: Preliminary information.
|
|---|
| 66 | * Comparison:: What file comparison means.
|
|---|
| 67 |
|
|---|
| 68 | * Output Formats:: Formats for two-way difference reports.
|
|---|
| 69 | * Incomplete Lines:: Lines that lack trailing newlines.
|
|---|
| 70 | * Comparing Directories:: Comparing files and directories.
|
|---|
| 71 | * Adjusting Output:: Making `diff' output prettier.
|
|---|
| 72 | * diff Performance:: Making `diff' smarter or faster.
|
|---|
| 73 |
|
|---|
| 74 | * Comparing Three Files:: Formats for three-way difference reports.
|
|---|
| 75 | * diff3 Merging:: Merging from a common ancestor.
|
|---|
| 76 |
|
|---|
| 77 | * Interactive Merging:: Interactive merging with `sdiff'.
|
|---|
| 78 |
|
|---|
| 79 | * Merging with patch:: Using `patch' to change old files into new ones.
|
|---|
| 80 | * Making Patches:: Tips for making and using patch distributions.
|
|---|
| 81 |
|
|---|
| 82 | * Invoking cmp:: Compare two files byte by byte.
|
|---|
| 83 | * Invoking diff:: Compare two files line by line.
|
|---|
| 84 | * Invoking diff3:: Compare three files line by line.
|
|---|
| 85 | * Invoking patch:: Apply a diff file to an original.
|
|---|
| 86 | * Invoking sdiff:: Side-by-side merge of file differences.
|
|---|
| 87 |
|
|---|
| 88 | * Standards conformance:: Conformance to the POSIX standard.
|
|---|
| 89 | * Projects:: If you've found a bug or other shortcoming.
|
|---|
| 90 |
|
|---|
| 91 | * Copying This Manual:: How to make copies of this manual.
|
|---|
| 92 | * Index:: Index.
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 | File: diff.info, Node: Overview, Next: Comparison, Prev: Top, Up: Top
|
|---|
| 96 |
|
|---|
| 97 | Overview
|
|---|
| 98 | ********
|
|---|
| 99 |
|
|---|
| 100 | Computer users often find occasion to ask how two files differ.
|
|---|
| 101 | Perhaps one file is a newer version of the other file. Or maybe the
|
|---|
| 102 | two files started out as identical copies but were changed by different
|
|---|
| 103 | people.
|
|---|
| 104 |
|
|---|
| 105 | You can use the `diff' command to show differences between two
|
|---|
| 106 | files, or each corresponding file in two directories. `diff' outputs
|
|---|
| 107 | differences between files line by line in any of several formats,
|
|---|
| 108 | selectable by command line options. This set of differences is often
|
|---|
| 109 | called a "diff" or "patch". For files that are identical, `diff'
|
|---|
| 110 | normally produces no output; for binary (non-text) files, `diff'
|
|---|
| 111 | normally reports only that they are different.
|
|---|
| 112 |
|
|---|
| 113 | You can use the `cmp' command to show the byte and line numbers
|
|---|
| 114 | where two files differ. `cmp' can also show all the bytes that differ
|
|---|
| 115 | between the two files, side by side. A way to compare two files
|
|---|
| 116 | character by character is the Emacs command `M-x compare-windows'.
|
|---|
| 117 | *Note Other Window: (emacs)Other Window, for more information on that
|
|---|
| 118 | command.
|
|---|
| 119 |
|
|---|
| 120 | You can use the `diff3' command to show differences among three
|
|---|
| 121 | files. When two people have made independent changes to a common
|
|---|
| 122 | original, `diff3' can report the differences between the original and
|
|---|
| 123 | the two changed versions, and can produce a merged file that contains
|
|---|
| 124 | both persons' changes together with warnings about conflicts.
|
|---|
| 125 |
|
|---|
| 126 | You can use the `sdiff' command to merge two files interactively.
|
|---|
| 127 |
|
|---|
| 128 | You can use the set of differences produced by `diff' to distribute
|
|---|
| 129 | updates to text files (such as program source code) to other people.
|
|---|
| 130 | This method is especially useful when the differences are small compared
|
|---|
| 131 | to the complete files. Given `diff' output, you can use the `patch'
|
|---|
| 132 | program to update, or "patch", a copy of the file. If you think of
|
|---|
| 133 | `diff' as subtracting one file from another to produce their
|
|---|
| 134 | difference, you can think of `patch' as adding the difference to one
|
|---|
| 135 | file to reproduce the other.
|
|---|
| 136 |
|
|---|
| 137 | This manual first concentrates on making diffs, and later shows how
|
|---|
| 138 | to use diffs to update files.
|
|---|
| 139 |
|
|---|
| 140 | GNU `diff' was written by Paul Eggert, Mike Haertel, David Hayes,
|
|---|
| 141 | Richard Stallman, and Len Tower. Wayne Davison designed and
|
|---|
| 142 | implemented the unified output format. The basic algorithm is described
|
|---|
| 143 | in "An O(ND) Difference Algorithm and its Variations", Eugene W. Myers,
|
|---|
| 144 | `Algorithmica' Vol. 1 No. 2, 1986, pp. 251-266; and in "A File
|
|---|
| 145 | Comparison Program", Webb Miller and Eugene W. Myers,
|
|---|
| 146 | `Software--Practice and Experience' Vol. 15 No. 11, 1985, pp. 1025-1040.
|
|---|
| 147 | The algorithm was independently discovered as described in "Algorithms
|
|---|
| 148 | for Approximate String Matching", E. Ukkonen, `Information and Control'
|
|---|
| 149 | Vol. 64, 1985, pp. 100-118.
|
|---|
| 150 |
|
|---|
| 151 | GNU `diff3' was written by Randy Smith. GNU `sdiff' was written by
|
|---|
| 152 | Thomas Lord. GNU `cmp' was written by Torbjorn Granlund and David
|
|---|
| 153 | MacKenzie.
|
|---|
| 154 |
|
|---|
| 155 | `patch' was written mainly by Larry Wall and Paul Eggert; several
|
|---|
| 156 | GNU enhancements were contributed by Wayne Davison and David MacKenzie.
|
|---|
| 157 | Parts of this manual are adapted from a manual page written by Larry
|
|---|
| 158 | Wall, with his permission.
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 | File: diff.info, Node: Comparison, Next: Output Formats, Prev: Overview, Up: Top
|
|---|
| 162 |
|
|---|
| 163 | What Comparison Means
|
|---|
| 164 | *********************
|
|---|
| 165 |
|
|---|
| 166 | There are several ways to think about the differences between two
|
|---|
| 167 | files. One way to think of the differences is as a series of lines
|
|---|
| 168 | that were deleted from, inserted in, or changed in one file to produce
|
|---|
| 169 | the other file. `diff' compares two files line by line, finds groups of
|
|---|
| 170 | lines that differ, and reports each group of differing lines. It can
|
|---|
| 171 | report the differing lines in several formats, which have different
|
|---|
| 172 | purposes.
|
|---|
| 173 |
|
|---|
| 174 | GNU `diff' can show whether files are different without detailing
|
|---|
| 175 | the differences. It also provides ways to suppress certain kinds of
|
|---|
| 176 | differences that are not important to you. Most commonly, such
|
|---|
| 177 | differences are changes in the amount of white space between words or
|
|---|
| 178 | lines. `diff' also provides ways to suppress differences in alphabetic
|
|---|
| 179 | case or in lines that match a regular expression that you provide.
|
|---|
| 180 | These options can accumulate; for example, you can ignore changes in
|
|---|
| 181 | both white space and alphabetic case.
|
|---|
| 182 |
|
|---|
| 183 | Another way to think of the differences between two files is as a
|
|---|
| 184 | sequence of pairs of bytes that can be either identical or different.
|
|---|
| 185 | `cmp' reports the differences between two files byte by byte, instead
|
|---|
| 186 | of line by line. As a result, it is often more useful than `diff' for
|
|---|
| 187 | comparing binary files. For text files, `cmp' is useful mainly when
|
|---|
| 188 | you want to know only whether two files are identical, or whether one
|
|---|
| 189 | file is a prefix of the other.
|
|---|
| 190 |
|
|---|
| 191 | To illustrate the effect that considering changes byte by byte can
|
|---|
| 192 | have compared with considering them line by line, think of what happens
|
|---|
| 193 | if a single newline character is added to the beginning of a file. If
|
|---|
| 194 | that file is then compared with an otherwise identical file that lacks
|
|---|
| 195 | the newline at the beginning, `diff' will report that a blank line has
|
|---|
| 196 | been added to the file, while `cmp' will report that almost every byte
|
|---|
| 197 | of the two files differs.
|
|---|
| 198 |
|
|---|
| 199 | `diff3' normally compares three input files line by line, finds
|
|---|
| 200 | groups of lines that differ, and reports each group of differing lines.
|
|---|
| 201 | Its output is designed to make it easy to inspect two different sets of
|
|---|
| 202 | changes to the same file.
|
|---|
| 203 |
|
|---|
| 204 | * Menu:
|
|---|
| 205 |
|
|---|
| 206 | * Hunks:: Groups of differing lines.
|
|---|
| 207 | * White Space:: Suppressing differences in white space.
|
|---|
| 208 | * Blank Lines:: Suppressing differences in blank lines.
|
|---|
| 209 | * Case Folding:: Suppressing differences in alphabetic case.
|
|---|
| 210 | * Specified Folding:: Suppressing differences that match regular expressions.
|
|---|
| 211 | * Brief:: Summarizing which files are different.
|
|---|
| 212 | * Binary:: Comparing binary files or forcing text comparisons.
|
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 | File: diff.info, Node: Hunks, Next: White Space, Up: Comparison
|
|---|
| 216 |
|
|---|
| 217 | Hunks
|
|---|
| 218 | =====
|
|---|
| 219 |
|
|---|
| 220 | When comparing two files, `diff' finds sequences of lines common to
|
|---|
| 221 | both files, interspersed with groups of differing lines called "hunks".
|
|---|
| 222 | Comparing two identical files yields one sequence of common lines and
|
|---|
| 223 | no hunks, because no lines differ. Comparing two entirely different
|
|---|
| 224 | files yields no common lines and one large hunk that contains all lines
|
|---|
| 225 | of both files. In general, there are many ways to match up lines
|
|---|
| 226 | between two given files. `diff' tries to minimize the total hunk size
|
|---|
| 227 | by finding large sequences of common lines interspersed with small
|
|---|
| 228 | hunks of differing lines.
|
|---|
| 229 |
|
|---|
| 230 | For example, suppose the file `F' contains the three lines `a', `b',
|
|---|
| 231 | `c', and the file `G' contains the same three lines in reverse order
|
|---|
| 232 | `c', `b', `a'. If `diff' finds the line `c' as common, then the command
|
|---|
| 233 | `diff F G' produces this output:
|
|---|
| 234 |
|
|---|
| 235 | 1,2d0
|
|---|
| 236 | < a
|
|---|
| 237 | < b
|
|---|
| 238 | 3a2,3
|
|---|
| 239 | > b
|
|---|
| 240 | > a
|
|---|
| 241 |
|
|---|
| 242 | But if `diff' notices the common line `b' instead, it produces this
|
|---|
| 243 | output:
|
|---|
| 244 |
|
|---|
| 245 | 1c1
|
|---|
| 246 | < a
|
|---|
| 247 | ---
|
|---|
| 248 | > c
|
|---|
| 249 | 3c3
|
|---|
| 250 | < c
|
|---|
| 251 | ---
|
|---|
| 252 | > a
|
|---|
| 253 |
|
|---|
| 254 | It is also possible to find `a' as the common line. `diff' does not
|
|---|
| 255 | always find an optimal matching between the files; it takes shortcuts
|
|---|
| 256 | to run faster. But its output is usually close to the shortest
|
|---|
| 257 | possible. You can adjust this tradeoff with the `--minimal' option
|
|---|
| 258 | (*note diff Performance::).
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 | File: diff.info, Node: White Space, Next: Blank Lines, Prev: Hunks, Up: Comparison
|
|---|
| 262 |
|
|---|
| 263 | Suppressing Differences in Blank and Tab Spacing
|
|---|
| 264 | ================================================
|
|---|
| 265 |
|
|---|
| 266 | The `-E' and `--ignore-tab-expansion' options ignore the distinction
|
|---|
| 267 | between tabs and spaces on input. A tab is considered to be equivalent
|
|---|
| 268 | to the number of spaces to the next tab stop. `diff' assumes that tab
|
|---|
| 269 | stops are set every 8 print columns.
|
|---|
| 270 |
|
|---|
| 271 | The `-b' and `--ignore-space-change' options are stronger. They
|
|---|
| 272 | ignore white space at line end, and consider all other sequences of one
|
|---|
| 273 | or more white space characters to be equivalent. With these options,
|
|---|
| 274 | `diff' considers the following two lines to be equivalent, where `$'
|
|---|
| 275 | denotes the line end:
|
|---|
| 276 |
|
|---|
| 277 | Here lyeth muche rychnesse in lytell space. -- John Heywood$
|
|---|
| 278 | Here lyeth muche rychnesse in lytell space. -- John Heywood $
|
|---|
| 279 |
|
|---|
| 280 | The `-w' and `--ignore-all-space' options are stronger still. They
|
|---|
| 281 | ignore difference even if one line has white space where the other line
|
|---|
| 282 | has none. "White space" characters include tab, newline, vertical tab,
|
|---|
| 283 | form feed, carriage return, and space; some locales may define
|
|---|
| 284 | additional characters to be white space. With these options, `diff'
|
|---|
| 285 | considers the following two lines to be equivalent, where `$' denotes
|
|---|
| 286 | the line end and `^M' denotes a carriage return:
|
|---|
| 287 |
|
|---|
| 288 | Here lyeth muche rychnesse in lytell space.-- John Heywood$
|
|---|
| 289 | He relyeth much erychnes seinly tells pace. --John Heywood ^M$
|
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 | File: diff.info, Node: Blank Lines, Next: Case Folding, Prev: White Space, Up: Comparison
|
|---|
| 293 |
|
|---|
| 294 | Suppressing Differences in Blank Lines
|
|---|
| 295 | ======================================
|
|---|
| 296 |
|
|---|
| 297 | The `-B' and `--ignore-blank-lines' options ignore insertions or
|
|---|
| 298 | deletions of blank lines. These options affect only lines that are
|
|---|
| 299 | completely empty; they do not affect lines that look empty but contain
|
|---|
| 300 | space or tab characters. With these options, for example, a file
|
|---|
| 301 | containing
|
|---|
| 302 | 1. A point is that which has no part.
|
|---|
| 303 |
|
|---|
| 304 | 2. A line is breadthless length.
|
|---|
| 305 | -- Euclid, The Elements, I
|
|---|
| 306 |
|
|---|
| 307 | is considered identical to a file containing
|
|---|
| 308 | 1. A point is that which has no part.
|
|---|
| 309 | 2. A line is breadthless length.
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 | -- Euclid, The Elements, I
|
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 | File: diff.info, Node: Case Folding, Next: Specified Folding, Prev: Blank Lines, Up: Comparison
|
|---|
| 316 |
|
|---|
| 317 | Suppressing Case Differences
|
|---|
| 318 | ============================
|
|---|
| 319 |
|
|---|
| 320 | GNU `diff' can treat lower case letters as equivalent to their upper
|
|---|
| 321 | case counterparts, so that, for example, it considers `Funky Stuff',
|
|---|
| 322 | `funky STUFF', and `fUNKy stuFf' to all be the same. To request this,
|
|---|
| 323 | use the `-i' or `--ignore-case' option.
|
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 | File: diff.info, Node: Specified Folding, Next: Brief, Prev: Case Folding, Up: Comparison
|
|---|
| 327 |
|
|---|
| 328 | Suppressing Lines Matching a Regular Expression
|
|---|
| 329 | ===============================================
|
|---|
| 330 |
|
|---|
| 331 | To ignore insertions and deletions of lines that match a
|
|---|
| 332 | `grep'-style regular expression, use the `-I REGEXP' or
|
|---|
| 333 | `--ignore-matching-lines=REGEXP' option. You should escape regular
|
|---|
| 334 | expressions that contain shell metacharacters to prevent the shell from
|
|---|
| 335 | expanding them. For example, `diff -I '^[[:digit:]]'' ignores all
|
|---|
| 336 | changes to lines beginning with a digit.
|
|---|
| 337 |
|
|---|
| 338 | However, `-I' only ignores the insertion or deletion of lines that
|
|---|
| 339 | contain the regular expression if every changed line in the hunk--every
|
|---|
| 340 | insertion and every deletion--matches the regular expression. In other
|
|---|
| 341 | words, for each nonignorable change, `diff' prints the complete set of
|
|---|
| 342 | changes in its vicinity, including the ignorable ones.
|
|---|
| 343 |
|
|---|
| 344 | You can specify more than one regular expression for lines to ignore
|
|---|
| 345 | by using more than one `-I' option. `diff' tries to match each line
|
|---|
| 346 | against each regular expression.
|
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 | File: diff.info, Node: Brief, Next: Binary, Prev: Specified Folding, Up: Comparison
|
|---|
| 350 |
|
|---|
| 351 | Summarizing Which Files Differ
|
|---|
| 352 | ==============================
|
|---|
| 353 |
|
|---|
| 354 | When you only want to find out whether files are different, and you
|
|---|
| 355 | don't care what the differences are, you can use the summary output
|
|---|
| 356 | format. In this format, instead of showing the differences between the
|
|---|
| 357 | files, `diff' simply reports whether files differ. The `-q' and
|
|---|
| 358 | `--brief' options select this output format.
|
|---|
| 359 |
|
|---|
| 360 | This format is especially useful when comparing the contents of two
|
|---|
| 361 | directories. It is also much faster than doing the normal line by line
|
|---|
| 362 | comparisons, because `diff' can stop analyzing the files as soon as it
|
|---|
| 363 | knows that there are any differences.
|
|---|
| 364 |
|
|---|
| 365 | You can also get a brief indication of whether two files differ by
|
|---|
| 366 | using `cmp'. For files that are identical, `cmp' produces no output.
|
|---|
| 367 | When the files differ, by default, `cmp' outputs the byte and line
|
|---|
| 368 | number where the first difference occurs. You can use the `-s' option
|
|---|
| 369 | to suppress that information, so that `cmp' produces no output and
|
|---|
| 370 | reports whether the files differ using only its exit status (*note
|
|---|
| 371 | Invoking cmp::).
|
|---|
| 372 |
|
|---|
| 373 | Unlike `diff', `cmp' cannot compare directories; it can only compare
|
|---|
| 374 | two files.
|
|---|
| 375 |
|
|---|
| 376 |
|
|---|
| 377 | File: diff.info, Node: Binary, Prev: Brief, Up: Comparison
|
|---|
| 378 |
|
|---|
| 379 | Binary Files and Forcing Text Comparisons
|
|---|
| 380 | =========================================
|
|---|
| 381 |
|
|---|
| 382 | If `diff' thinks that either of the two files it is comparing is
|
|---|
| 383 | binary (a non-text file), it normally treats that pair of files much as
|
|---|
| 384 | if the summary output format had been selected (*note Brief::), and
|
|---|
| 385 | reports only that the binary files are different. This is because line
|
|---|
| 386 | by line comparisons are usually not meaningful for binary files.
|
|---|
| 387 |
|
|---|
| 388 | `diff' determines whether a file is text or binary by checking the
|
|---|
| 389 | first few bytes in the file; the exact number of bytes is system
|
|---|
| 390 | dependent, but it is typically several thousand. If every byte in that
|
|---|
| 391 | part of the file is non-null, `diff' considers the file to be text;
|
|---|
| 392 | otherwise it considers the file to be binary.
|
|---|
| 393 |
|
|---|
| 394 | Sometimes you might want to force `diff' to consider files to be
|
|---|
| 395 | text. For example, you might be comparing text files that contain null
|
|---|
| 396 | characters; `diff' would erroneously decide that those are non-text
|
|---|
| 397 | files. Or you might be comparing documents that are in a format used
|
|---|
| 398 | by a word processing system that uses null characters to indicate
|
|---|
| 399 | special formatting. You can force `diff' to consider all files to be
|
|---|
| 400 | text files, and compare them line by line, by using the `-a' or
|
|---|
| 401 | `--text' option. If the files you compare using this option do not in
|
|---|
| 402 | fact contain text, they will probably contain few newline characters,
|
|---|
| 403 | and the `diff' output will consist of hunks showing differences between
|
|---|
| 404 | long lines of whatever characters the files contain.
|
|---|
| 405 |
|
|---|
| 406 | You can also force `diff' to consider all files to be binary files,
|
|---|
| 407 | and report only whether they differ (but not how). Use the `-q' or
|
|---|
| 408 | `--brief' option for this.
|
|---|
| 409 |
|
|---|
| 410 | Differing binary files are considered to cause trouble because the
|
|---|
| 411 | resulting `diff' output does not capture all the differences. This
|
|---|
| 412 | trouble causes `diff' to exit with status 2. However, this trouble
|
|---|
| 413 | cannot occur with the `--a' or `--text' option, or with the `-q' or
|
|---|
| 414 | `--brief' option, as these options both cause `diff' to treat binary
|
|---|
| 415 | files like text files.
|
|---|
| 416 |
|
|---|
| 417 | In operating systems that distinguish between text and binary files,
|
|---|
| 418 | `diff' normally reads and writes all data as text. Use the `--binary'
|
|---|
| 419 | option to force `diff' to read and write binary data instead. This
|
|---|
| 420 | option has no effect on a POSIX-compliant system like GNU or
|
|---|
| 421 | traditional Unix. However, many personal computer operating systems
|
|---|
| 422 | represent the end of a line with a carriage return followed by a
|
|---|
| 423 | newline. On such systems, `diff' normally ignores these carriage
|
|---|
| 424 | returns on input and generates them at the end of each output line, but
|
|---|
| 425 | with the `--binary' option `diff' treats each carriage return as just
|
|---|
| 426 | another input character, and does not generate a carriage return at the
|
|---|
| 427 | end of each output line. This can be useful when dealing with non-text
|
|---|
| 428 | files that are meant to be interchanged with POSIX-compliant systems.
|
|---|
| 429 |
|
|---|
| 430 | The `--strip-trailing-cr' causes `diff' to treat input lines that
|
|---|
| 431 | end in carriage return followed by newline as if they end in plain
|
|---|
| 432 | newline. This can be useful when comparing text that is imperfectly
|
|---|
| 433 | imported from many personal computer operating systems. This option
|
|---|
| 434 | affects how lines are read, which in turn affects how they are compared
|
|---|
| 435 | and output.
|
|---|
| 436 |
|
|---|
| 437 | If you want to compare two files byte by byte, you can use the `cmp'
|
|---|
| 438 | program with the `-l' option to show the values of each differing byte
|
|---|
| 439 | in the two files. With GNU `cmp', you can also use the `-b' option to
|
|---|
| 440 | show the ASCII representation of those bytes. *Note Invoking cmp::,
|
|---|
| 441 | for more information.
|
|---|
| 442 |
|
|---|
| 443 | If `diff3' thinks that any of the files it is comparing is binary (a
|
|---|
| 444 | non-text file), it normally reports an error, because such comparisons
|
|---|
| 445 | are usually not useful. `diff3' uses the same test as `diff' to decide
|
|---|
| 446 | whether a file is binary. As with `diff', if the input files contain a
|
|---|
| 447 | few non-text bytes but otherwise are like text files, you can force
|
|---|
| 448 | `diff3' to consider all files to be text files and compare them line by
|
|---|
| 449 | line by using the `-a' or `--text' options.
|
|---|
| 450 |
|
|---|
| 451 |
|
|---|
| 452 | File: diff.info, Node: Output Formats, Next: Incomplete Lines, Prev: Comparison, Up: Top
|
|---|
| 453 |
|
|---|
| 454 | `diff' Output Formats
|
|---|
| 455 | *********************
|
|---|
| 456 |
|
|---|
| 457 | `diff' has several mutually exclusive options for output format.
|
|---|
| 458 | The following sections describe each format, illustrating how `diff'
|
|---|
| 459 | reports the differences between two sample input files.
|
|---|
| 460 |
|
|---|
| 461 | * Menu:
|
|---|
| 462 |
|
|---|
| 463 | * Sample diff Input:: Sample `diff' input files for examples.
|
|---|
| 464 | * Normal:: Showing differences without surrounding text.
|
|---|
| 465 | * Context:: Showing differences with the surrounding text.
|
|---|
| 466 | * Side by Side:: Showing differences in two columns.
|
|---|
| 467 | * Scripts:: Generating scripts for other programs.
|
|---|
| 468 | * If-then-else:: Merging files with if-then-else.
|
|---|
| 469 |
|
|---|
| 470 |
|
|---|
| 471 | File: diff.info, Node: Sample diff Input, Next: Normal, Up: Output Formats
|
|---|
| 472 |
|
|---|
| 473 | Two Sample Input Files
|
|---|
| 474 | ======================
|
|---|
| 475 |
|
|---|
| 476 | Here are two sample files that we will use in numerous examples to
|
|---|
| 477 | illustrate the output of `diff' and how various options can change it.
|
|---|
| 478 |
|
|---|
| 479 | This is the file `lao':
|
|---|
| 480 |
|
|---|
| 481 | The Way that can be told of is not the eternal Way;
|
|---|
| 482 | The name that can be named is not the eternal name.
|
|---|
| 483 | The Nameless is the origin of Heaven and Earth;
|
|---|
| 484 | The Named is the mother of all things.
|
|---|
| 485 | Therefore let there always be non-being,
|
|---|
| 486 | so we may see their subtlety,
|
|---|
| 487 | And let there always be being,
|
|---|
| 488 | so we may see their outcome.
|
|---|
| 489 | The two are the same,
|
|---|
| 490 | But after they are produced,
|
|---|
| 491 | they have different names.
|
|---|
| 492 |
|
|---|
| 493 | This is the file `tzu':
|
|---|
| 494 |
|
|---|
| 495 | The Nameless is the origin of Heaven and Earth;
|
|---|
| 496 | The named is the mother of all things.
|
|---|
| 497 |
|
|---|
| 498 | Therefore let there always be non-being,
|
|---|
| 499 | so we may see their subtlety,
|
|---|
| 500 | And let there always be being,
|
|---|
| 501 | so we may see their outcome.
|
|---|
| 502 | The two are the same,
|
|---|
| 503 | But after they are produced,
|
|---|
| 504 | they have different names.
|
|---|
| 505 | They both may be called deep and profound.
|
|---|
| 506 | Deeper and more profound,
|
|---|
| 507 | The door of all subtleties!
|
|---|
| 508 |
|
|---|
| 509 | In this example, the first hunk contains just the first two lines of
|
|---|
| 510 | `lao', the second hunk contains the fourth line of `lao' opposing the
|
|---|
| 511 | second and third lines of `tzu', and the last hunk contains just the
|
|---|
| 512 | last three lines of `tzu'.
|
|---|
| 513 |
|
|---|
| 514 |
|
|---|
| 515 | File: diff.info, Node: Normal, Next: Context, Prev: Sample diff Input, Up: Output Formats
|
|---|
| 516 |
|
|---|
| 517 | Showing Differences Without Context
|
|---|
| 518 | ===================================
|
|---|
| 519 |
|
|---|
| 520 | The "normal" `diff' output format shows each hunk of differences
|
|---|
| 521 | without any surrounding context. Sometimes such output is the clearest
|
|---|
| 522 | way to see how lines have changed, without the clutter of nearby
|
|---|
| 523 | unchanged lines (although you can get similar results with the context
|
|---|
| 524 | or unified formats by using 0 lines of context). However, this format
|
|---|
| 525 | is no longer widely used for sending out patches; for that purpose, the
|
|---|
| 526 | context format (*note Context Format::) and the unified format (*note
|
|---|
| 527 | Unified Format::) are superior. Normal format is the default for
|
|---|
| 528 | compatibility with older versions of `diff' and the POSIX standard.
|
|---|
| 529 | Use the `--normal' option to select this output format explicitly.
|
|---|
| 530 |
|
|---|
| 531 | * Menu:
|
|---|
| 532 |
|
|---|
| 533 | * Detailed Normal:: A detailed description of normal output format.
|
|---|
| 534 | * Example Normal:: Sample output in the normal format.
|
|---|
| 535 |
|
|---|
| 536 |
|
|---|
| 537 | File: diff.info, Node: Detailed Normal, Next: Example Normal, Up: Normal
|
|---|
| 538 |
|
|---|
| 539 | Detailed Description of Normal Format
|
|---|
| 540 | -------------------------------------
|
|---|
| 541 |
|
|---|
| 542 | The normal output format consists of one or more hunks of
|
|---|
| 543 | differences; each hunk shows one area where the files differ. Normal
|
|---|
| 544 | format hunks look like this:
|
|---|
| 545 |
|
|---|
| 546 | CHANGE-COMMAND
|
|---|
| 547 | < FROM-FILE-LINE
|
|---|
| 548 | < FROM-FILE-LINE...
|
|---|
| 549 | ---
|
|---|
| 550 | > TO-FILE-LINE
|
|---|
| 551 | > TO-FILE-LINE...
|
|---|
| 552 |
|
|---|
| 553 | There are three types of change commands. Each consists of a line
|
|---|
| 554 | number or comma-separated range of lines in the first file, a single
|
|---|
| 555 | character indicating the kind of change to make, and a line number or
|
|---|
| 556 | comma-separated range of lines in the second file. All line numbers are
|
|---|
| 557 | the original line numbers in each file. The types of change commands
|
|---|
| 558 | are:
|
|---|
| 559 |
|
|---|
| 560 | `LaR'
|
|---|
| 561 | Add the lines in range R of the second file after line L of the
|
|---|
| 562 | first file. For example, `8a12,15' means append lines 12-15 of
|
|---|
| 563 | file 2 after line 8 of file 1; or, if changing file 2 into file 1,
|
|---|
| 564 | delete lines 12-15 of file 2.
|
|---|
| 565 |
|
|---|
| 566 | `FcT'
|
|---|
| 567 | Replace the lines in range F of the first file with lines in range
|
|---|
| 568 | T of the second file. This is like a combined add and delete, but
|
|---|
| 569 | more compact. For example, `5,7c8,10' means change lines 5-7 of
|
|---|
| 570 | file 1 to read as lines 8-10 of file 2; or, if changing file 2 into
|
|---|
| 571 | file 1, change lines 8-10 of file 2 to read as lines 5-7 of file 1.
|
|---|
| 572 |
|
|---|
| 573 | `RdL'
|
|---|
| 574 | Delete the lines in range R from the first file; line L is where
|
|---|
| 575 | they would have appeared in the second file had they not been
|
|---|
| 576 | deleted. For example, `5,7d3' means delete lines 5-7 of file 1;
|
|---|
| 577 | or, if changing file 2 into file 1, append lines 5-7 of file 1
|
|---|
| 578 | after line 3 of file 2.
|
|---|
| 579 |
|
|---|
| 580 |
|
|---|
| 581 | File: diff.info, Node: Example Normal, Prev: Detailed Normal, Up: Normal
|
|---|
| 582 |
|
|---|
| 583 | An Example of Normal Format
|
|---|
| 584 | ---------------------------
|
|---|
| 585 |
|
|---|
| 586 | Here is the output of the command `diff lao tzu' (*note Sample diff
|
|---|
| 587 | Input::, for the complete contents of the two files). Notice that it
|
|---|
| 588 | shows only the lines that are different between the two files.
|
|---|
| 589 |
|
|---|
| 590 | 1,2d0
|
|---|
| 591 | < The Way that can be told of is not the eternal Way;
|
|---|
| 592 | < The name that can be named is not the eternal name.
|
|---|
| 593 | 4c2,3
|
|---|
| 594 | < The Named is the mother of all things.
|
|---|
| 595 | ---
|
|---|
| 596 | > The named is the mother of all things.
|
|---|
| 597 | >
|
|---|
| 598 | 11a11,13
|
|---|
| 599 | > They both may be called deep and profound.
|
|---|
| 600 | > Deeper and more profound,
|
|---|
| 601 | > The door of all subtleties!
|
|---|
| 602 |
|
|---|
| 603 |
|
|---|
| 604 | File: diff.info, Node: Context, Next: Side by Side, Prev: Normal, Up: Output Formats
|
|---|
| 605 |
|
|---|
| 606 | Showing Differences in Their Context
|
|---|
| 607 | ====================================
|
|---|
| 608 |
|
|---|
| 609 | Usually, when you are looking at the differences between files, you
|
|---|
| 610 | will also want to see the parts of the files near the lines that
|
|---|
| 611 | differ, to help you understand exactly what has changed. These nearby
|
|---|
| 612 | parts of the files are called the "context".
|
|---|
| 613 |
|
|---|
| 614 | GNU `diff' provides two output formats that show context around the
|
|---|
| 615 | differing lines: "context format" and "unified format". It can
|
|---|
| 616 | optionally show in which function or section of the file the differing
|
|---|
| 617 | lines are found.
|
|---|
| 618 |
|
|---|
| 619 | If you are distributing new versions of files to other people in the
|
|---|
| 620 | form of `diff' output, you should use one of the output formats that
|
|---|
| 621 | show context so that they can apply the diffs even if they have made
|
|---|
| 622 | small changes of their own to the files. `patch' can apply the diffs
|
|---|
| 623 | in this case by searching in the files for the lines of context around
|
|---|
| 624 | the differing lines; if those lines are actually a few lines away from
|
|---|
| 625 | where the diff says they are, `patch' can adjust the line numbers
|
|---|
| 626 | accordingly and still apply the diff correctly. *Note Imperfect::, for
|
|---|
| 627 | more information on using `patch' to apply imperfect diffs.
|
|---|
| 628 |
|
|---|
| 629 | * Menu:
|
|---|
| 630 |
|
|---|
| 631 | * Context Format:: An output format that shows surrounding lines.
|
|---|
| 632 | * Unified Format:: A more compact output format that shows context.
|
|---|
| 633 | * Sections:: Showing which sections of the files differences are in.
|
|---|
| 634 | * Alternate Names:: Showing alternate file names in context headers.
|
|---|
| 635 |
|
|---|
| 636 |
|
|---|
| 637 | File: diff.info, Node: Context Format, Next: Unified Format, Up: Context
|
|---|
| 638 |
|
|---|
| 639 | Context Format
|
|---|
| 640 | --------------
|
|---|
| 641 |
|
|---|
| 642 | The context output format shows several lines of context around the
|
|---|
| 643 | lines that differ. It is the standard format for distributing updates
|
|---|
| 644 | to source code.
|
|---|
| 645 |
|
|---|
| 646 | To select this output format, use the `-C LINES',
|
|---|
| 647 | `--context[=LINES]', or `-c' option. The argument LINES that some of
|
|---|
| 648 | these options take is the number of lines of context to show. If you
|
|---|
| 649 | do not specify LINES, it defaults to three. For proper operation,
|
|---|
| 650 | `patch' typically needs at least two lines of context.
|
|---|
| 651 |
|
|---|
| 652 | * Menu:
|
|---|
| 653 |
|
|---|
| 654 | * Detailed Context:: A detailed description of the context output format.
|
|---|
| 655 | * Example Context:: Sample output in context format.
|
|---|
| 656 | * Less Context:: Another sample with less context.
|
|---|
| 657 |
|
|---|
| 658 |
|
|---|
| 659 | File: diff.info, Node: Detailed Context, Next: Example Context, Up: Context Format
|
|---|
| 660 |
|
|---|
| 661 | Detailed Description of Context Format
|
|---|
| 662 | ......................................
|
|---|
| 663 |
|
|---|
| 664 | The context output format starts with a two-line header, which looks
|
|---|
| 665 | like this:
|
|---|
| 666 |
|
|---|
| 667 | *** FROM-FILE FROM-FILE-MODIFICATION-TIME
|
|---|
| 668 | --- TO-FILE TO-FILE-MODIFICATION TIME
|
|---|
| 669 |
|
|---|
| 670 | The time stamp normally looks like `2002-02-21 23:30:39.942229878
|
|---|
| 671 | -0800' to indicate the date, time with fractional seconds, and time
|
|---|
| 672 | zone in Internet RFC 2822 format
|
|---|
| 673 | (ftp://ftp.isi.edu/in-notes/rfc2822.txt). However, a traditional time
|
|---|
| 674 | stamp like `Thu Feb 21 23:30:39 2002' is used if the `LC_TIME' locale
|
|---|
| 675 | category is either `C' or `POSIX'.
|
|---|
| 676 |
|
|---|
| 677 | You can change the header's content with the `--label=LABEL' option;
|
|---|
| 678 | see *Note Alternate Names::.
|
|---|
| 679 |
|
|---|
| 680 | Next come one or more hunks of differences; each hunk shows one area
|
|---|
| 681 | where the files differ. Context format hunks look like this:
|
|---|
| 682 |
|
|---|
| 683 | ***************
|
|---|
| 684 | *** FROM-FILE-LINE-RANGE ****
|
|---|
| 685 | FROM-FILE-LINE
|
|---|
| 686 | FROM-FILE-LINE...
|
|---|
| 687 | --- TO-FILE-LINE-RANGE ----
|
|---|
| 688 | TO-FILE-LINE
|
|---|
| 689 | TO-FILE-LINE...
|
|---|
| 690 |
|
|---|
| 691 | The lines of context around the lines that differ start with two
|
|---|
| 692 | space characters. The lines that differ between the two files start
|
|---|
| 693 | with one of the following indicator characters, followed by a space
|
|---|
| 694 | character:
|
|---|
| 695 |
|
|---|
| 696 | `!'
|
|---|
| 697 | A line that is part of a group of one or more lines that changed
|
|---|
| 698 | between the two files. There is a corresponding group of lines
|
|---|
| 699 | marked with `!' in the part of this hunk for the other file.
|
|---|
| 700 |
|
|---|
| 701 | `+'
|
|---|
| 702 | An "inserted" line in the second file that corresponds to nothing
|
|---|
| 703 | in the first file.
|
|---|
| 704 |
|
|---|
| 705 | `-'
|
|---|
| 706 | A "deleted" line in the first file that corresponds to nothing in
|
|---|
| 707 | the second file.
|
|---|
| 708 |
|
|---|
| 709 | If all of the changes in a hunk are insertions, the lines of
|
|---|
| 710 | FROM-FILE are omitted. If all of the changes are deletions, the lines
|
|---|
| 711 | of TO-FILE are omitted.
|
|---|
| 712 |
|
|---|
| 713 |
|
|---|
| 714 | File: diff.info, Node: Example Context, Next: Less Context, Prev: Detailed Context, Up: Context Format
|
|---|
| 715 |
|
|---|
| 716 | An Example of Context Format
|
|---|
| 717 | ............................
|
|---|
| 718 |
|
|---|
| 719 | Here is the output of `diff -c lao tzu' (*note Sample diff Input::,
|
|---|
| 720 | for the complete contents of the two files). Notice that up to three
|
|---|
| 721 | lines that are not different are shown around each line that is
|
|---|
| 722 | different; they are the context lines. Also notice that the first two
|
|---|
| 723 | hunks have run together, because their contents overlap.
|
|---|
| 724 |
|
|---|
| 725 | *** lao 2002-02-21 23:30:39.942229878 -0800
|
|---|
| 726 | --- tzu 2002-02-21 23:30:50.442260588 -0800
|
|---|
| 727 | ***************
|
|---|
| 728 | *** 1,7 ****
|
|---|
| 729 | - The Way that can be told of is not the eternal Way;
|
|---|
| 730 | - The name that can be named is not the eternal name.
|
|---|
| 731 | The Nameless is the origin of Heaven and Earth;
|
|---|
| 732 | ! The Named is the mother of all things.
|
|---|
| 733 | Therefore let there always be non-being,
|
|---|
| 734 | so we may see their subtlety,
|
|---|
| 735 | And let there always be being,
|
|---|
| 736 | --- 1,6 ----
|
|---|
| 737 | The Nameless is the origin of Heaven and Earth;
|
|---|
| 738 | ! The named is the mother of all things.
|
|---|
| 739 | !
|
|---|
| 740 | Therefore let there always be non-being,
|
|---|
| 741 | so we may see their subtlety,
|
|---|
| 742 | And let there always be being,
|
|---|
| 743 | ***************
|
|---|
| 744 | *** 9,11 ****
|
|---|
| 745 | --- 8,13 ----
|
|---|
| 746 | The two are the same,
|
|---|
| 747 | But after they are produced,
|
|---|
| 748 | they have different names.
|
|---|
| 749 | + They both may be called deep and profound.
|
|---|
| 750 | + Deeper and more profound,
|
|---|
| 751 | + The door of all subtleties!
|
|---|
| 752 |
|
|---|
| 753 |
|
|---|
| 754 | File: diff.info, Node: Less Context, Prev: Example Context, Up: Context Format
|
|---|
| 755 |
|
|---|
| 756 | An Example of Context Format with Less Context
|
|---|
| 757 | ..............................................
|
|---|
| 758 |
|
|---|
| 759 | Here is the output of `diff -C 1 lao tzu' (*note Sample diff
|
|---|
| 760 | Input::, for the complete contents of the two files). Notice that at
|
|---|
| 761 | most one context line is reported here.
|
|---|
| 762 |
|
|---|
| 763 | *** lao 2002-02-21 23:30:39.942229878 -0800
|
|---|
| 764 | --- tzu 2002-02-21 23:30:50.442260588 -0800
|
|---|
| 765 | ***************
|
|---|
| 766 | *** 1,5 ****
|
|---|
| 767 | - The Way that can be told of is not the eternal Way;
|
|---|
| 768 | - The name that can be named is not the eternal name.
|
|---|
| 769 | The Nameless is the origin of Heaven and Earth;
|
|---|
| 770 | ! The Named is the mother of all things.
|
|---|
| 771 | Therefore let there always be non-being,
|
|---|
| 772 | --- 1,4 ----
|
|---|
| 773 | The Nameless is the origin of Heaven and Earth;
|
|---|
| 774 | ! The named is the mother of all things.
|
|---|
| 775 | !
|
|---|
| 776 | Therefore let there always be non-being,
|
|---|
| 777 | ***************
|
|---|
| 778 | *** 11 ****
|
|---|
| 779 | --- 10,13 ----
|
|---|
| 780 | they have different names.
|
|---|
| 781 | + They both may be called deep and profound.
|
|---|
| 782 | + Deeper and more profound,
|
|---|
| 783 | + The door of all subtleties!
|
|---|
| 784 |
|
|---|
| 785 |
|
|---|
| 786 | File: diff.info, Node: Unified Format, Next: Sections, Prev: Context Format, Up: Context
|
|---|
| 787 |
|
|---|
| 788 | Unified Format
|
|---|
| 789 | --------------
|
|---|
| 790 |
|
|---|
| 791 | The unified output format is a variation on the context format that
|
|---|
| 792 | is more compact because it omits redundant context lines. To select
|
|---|
| 793 | this output format, use the `-U LINES', `--unified[=LINES]', or `-u'
|
|---|
| 794 | option. The argument LINES is the number of lines of context to show.
|
|---|
| 795 | When it is not given, it defaults to three.
|
|---|
| 796 |
|
|---|
| 797 | At present, only GNU `diff' can produce this format and only GNU
|
|---|
| 798 | `patch' can automatically apply diffs in this format. For proper
|
|---|
| 799 | operation, `patch' typically needs at least three lines of context.
|
|---|
| 800 |
|
|---|
| 801 | * Menu:
|
|---|
| 802 |
|
|---|
| 803 | * Detailed Unified:: A detailed description of unified format.
|
|---|
| 804 | * Example Unified:: Sample output in unified format.
|
|---|
| 805 |
|
|---|
| 806 |
|
|---|
| 807 | File: diff.info, Node: Detailed Unified, Next: Example Unified, Up: Unified Format
|
|---|
| 808 |
|
|---|
| 809 | Detailed Description of Unified Format
|
|---|
| 810 | ......................................
|
|---|
| 811 |
|
|---|
| 812 | The unified output format starts with a two-line header, which looks
|
|---|
| 813 | like this:
|
|---|
| 814 |
|
|---|
| 815 | --- FROM-FILE FROM-FILE-MODIFICATION-TIME
|
|---|
| 816 | +++ TO-FILE TO-FILE-MODIFICATION-TIME
|
|---|
| 817 |
|
|---|
| 818 | The time stamp looks like `2002-02-21 23:30:39.942229878 -0800' to
|
|---|
| 819 | indicate the date, time with fractional seconds, and time zone.
|
|---|
| 820 |
|
|---|
| 821 | You can change the header's content with the `--label=LABEL' option;
|
|---|
| 822 | see *Note Alternate Names::.
|
|---|
| 823 |
|
|---|
| 824 | Next come one or more hunks of differences; each hunk shows one area
|
|---|
| 825 | where the files differ. Unified format hunks look like this:
|
|---|
| 826 |
|
|---|
| 827 | @@ FROM-FILE-RANGE TO-FILE-RANGE @@
|
|---|
| 828 | LINE-FROM-EITHER-FILE
|
|---|
| 829 | LINE-FROM-EITHER-FILE...
|
|---|
| 830 |
|
|---|
| 831 | The lines common to both files begin with a space character. The
|
|---|
| 832 | lines that actually differ between the two files have one of the
|
|---|
| 833 | following indicator characters in the left print column:
|
|---|
| 834 |
|
|---|
| 835 | `+'
|
|---|
| 836 | A line was added here to the first file.
|
|---|
| 837 |
|
|---|
| 838 | `-'
|
|---|
| 839 | A line was removed here from the first file.
|
|---|
| 840 |
|
|---|
| 841 |
|
|---|
| 842 | File: diff.info, Node: Example Unified, Prev: Detailed Unified, Up: Unified Format
|
|---|
| 843 |
|
|---|
| 844 | An Example of Unified Format
|
|---|
| 845 | ............................
|
|---|
| 846 |
|
|---|
| 847 | Here is the output of the command `diff -u lao tzu' (*note Sample
|
|---|
| 848 | diff Input::, for the complete contents of the two files):
|
|---|
| 849 |
|
|---|
| 850 | --- lao 2002-02-21 23:30:39.942229878 -0800
|
|---|
| 851 | +++ tzu 2002-02-21 23:30:50.442260588 -0800
|
|---|
| 852 | @@ -1,7 +1,6 @@
|
|---|
| 853 | -The Way that can be told of is not the eternal Way;
|
|---|
| 854 | -The name that can be named is not the eternal name.
|
|---|
| 855 | The Nameless is the origin of Heaven and Earth;
|
|---|
| 856 | -The Named is the mother of all things.
|
|---|
| 857 | +The named is the mother of all things.
|
|---|
| 858 | +
|
|---|
| 859 | Therefore let there always be non-being,
|
|---|
| 860 | so we may see their subtlety,
|
|---|
| 861 | And let there always be being,
|
|---|
| 862 | @@ -9,3 +8,6 @@
|
|---|
| 863 | The two are the same,
|
|---|
| 864 | But after they are produced,
|
|---|
| 865 | they have different names.
|
|---|
| 866 | +They both may be called deep and profound.
|
|---|
| 867 | +Deeper and more profound,
|
|---|
| 868 | +The door of all subtleties!
|
|---|
| 869 |
|
|---|
| 870 |
|
|---|
| 871 | File: diff.info, Node: Sections, Next: Alternate Names, Prev: Unified Format, Up: Context
|
|---|
| 872 |
|
|---|
| 873 | Showing Which Sections Differences Are in
|
|---|
| 874 | -----------------------------------------
|
|---|
| 875 |
|
|---|
| 876 | Sometimes you might want to know which part of the files each change
|
|---|
| 877 | falls in. If the files are source code, this could mean which function
|
|---|
| 878 | was changed. If the files are documents, it could mean which chapter or
|
|---|
| 879 | appendix was changed. GNU `diff' can show this by displaying the
|
|---|
| 880 | nearest section heading line that precedes the differing lines. Which
|
|---|
| 881 | lines are "section headings" is determined by a regular expression.
|
|---|
| 882 |
|
|---|
| 883 | * Menu:
|
|---|
| 884 |
|
|---|
| 885 | * Specified Headings:: Showing headings that match regular expressions.
|
|---|
| 886 | * C Function Headings:: Showing headings of C functions.
|
|---|
| 887 |
|
|---|
| 888 |
|
|---|
| 889 | File: diff.info, Node: Specified Headings, Next: C Function Headings, Up: Sections
|
|---|
| 890 |
|
|---|
| 891 | Showing Lines That Match Regular Expressions
|
|---|
| 892 | ............................................
|
|---|
| 893 |
|
|---|
| 894 | To show in which sections differences occur for files that are not
|
|---|
| 895 | source code for C or similar languages, use the `-F REGEXP' or
|
|---|
| 896 | `--show-function-line=REGEXP' option. `diff' considers lines that
|
|---|
| 897 | match the `grep'-style regular expression REGEXP to be the beginning of
|
|---|
| 898 | a section of the file. Here are suggested regular expressions for some
|
|---|
| 899 | common languages:
|
|---|
| 900 |
|
|---|
| 901 | `^[[:alpha:]$_]'
|
|---|
| 902 | C, C++, Prolog
|
|---|
| 903 |
|
|---|
| 904 | `^('
|
|---|
| 905 | Lisp
|
|---|
| 906 |
|
|---|
| 907 | `^@node'
|
|---|
| 908 | Texinfo
|
|---|
| 909 |
|
|---|
| 910 | This option does not automatically select an output format; in order
|
|---|
| 911 | to use it, you must select the context format (*note Context Format::)
|
|---|
| 912 | or unified format (*note Unified Format::). In other output formats it
|
|---|
| 913 | has no effect.
|
|---|
| 914 |
|
|---|
| 915 | The `-F' and `--show-function-line' options find the nearest
|
|---|
| 916 | unchanged line that precedes each hunk of differences and matches the
|
|---|
| 917 | given regular expression. Then they add that line to the end of the
|
|---|
| 918 | line of asterisks in the context format, or to the `@@' line in unified
|
|---|
| 919 | format. If no matching line exists, they leave the output for that
|
|---|
| 920 | hunk unchanged. If that line is more than 40 characters long, they
|
|---|
| 921 | output only the first 40 characters. You can specify more than one
|
|---|
| 922 | regular expression for such lines; `diff' tries to match each line
|
|---|
| 923 | against each regular expression, starting with the last one given. This
|
|---|
| 924 | means that you can use `-p' and `-F' together, if you wish.
|
|---|
| 925 |
|
|---|
| 926 |
|
|---|
| 927 | File: diff.info, Node: C Function Headings, Prev: Specified Headings, Up: Sections
|
|---|
| 928 |
|
|---|
| 929 | Showing C Function Headings
|
|---|
| 930 | ...........................
|
|---|
| 931 |
|
|---|
| 932 | To show in which functions differences occur for C and similar
|
|---|
| 933 | languages, you can use the `-p' or `--show-c-function' option. This
|
|---|
| 934 | option automatically defaults to the context output format (*note
|
|---|
| 935 | Context Format::), with the default number of lines of context. You
|
|---|
| 936 | can override that number with `-C LINES' elsewhere in the command line.
|
|---|
| 937 | You can override both the format and the number with `-U LINES'
|
|---|
| 938 | elsewhere in the command line.
|
|---|
| 939 |
|
|---|
| 940 | The `-p' and `--show-c-function' options are equivalent to `-F
|
|---|
| 941 | '^[[:alpha:]$_]'' if the unified format is specified, otherwise `-c -F
|
|---|
| 942 | '^[[:alpha:]$_]'' (*note Specified Headings::). GNU `diff' provides
|
|---|
| 943 | them for the sake of convenience.
|
|---|
| 944 |
|
|---|
| 945 |
|
|---|
| 946 | File: diff.info, Node: Alternate Names, Prev: Sections, Up: Context
|
|---|
| 947 |
|
|---|
| 948 | Showing Alternate File Names
|
|---|
| 949 | ----------------------------
|
|---|
| 950 |
|
|---|
| 951 | If you are comparing two files that have meaningless or uninformative
|
|---|
| 952 | names, you might want `diff' to show alternate names in the header of
|
|---|
| 953 | the context and unified output formats. To do this, use the
|
|---|
| 954 | `--label=LABEL' option. The first time you give this option, its
|
|---|
| 955 | argument replaces the name and date of the first file in the header;
|
|---|
| 956 | the second time, its argument replaces the name and date of the second
|
|---|
| 957 | file. If you give this option more than twice, `diff' reports an
|
|---|
| 958 | error. The `--label' option does not affect the file names in the `pr'
|
|---|
| 959 | header when the `-l' or `--paginate' option is used (*note
|
|---|
| 960 | Pagination::).
|
|---|
| 961 |
|
|---|
| 962 | Here are the first two lines of the output from `diff -C 2
|
|---|
| 963 | --label=original --label=modified lao tzu':
|
|---|
| 964 |
|
|---|
| 965 | *** original
|
|---|
| 966 | --- modified
|
|---|
| 967 |
|
|---|
| 968 |
|
|---|
| 969 | File: diff.info, Node: Side by Side, Next: Scripts, Prev: Context, Up: Output Formats
|
|---|
| 970 |
|
|---|
| 971 | Showing Differences Side by Side
|
|---|
| 972 | ================================
|
|---|
| 973 |
|
|---|
| 974 | `diff' can produce a side by side difference listing of two files.
|
|---|
| 975 | The files are listed in two columns with a gutter between them. The
|
|---|
| 976 | gutter contains one of the following markers:
|
|---|
| 977 |
|
|---|
| 978 | white space
|
|---|
| 979 | The corresponding lines are in common. That is, either the lines
|
|---|
| 980 | are identical, or the difference is ignored because of one of the
|
|---|
| 981 | `--ignore' options (*note White Space::).
|
|---|
| 982 |
|
|---|
| 983 | `|'
|
|---|
| 984 | The corresponding lines differ, and they are either both complete
|
|---|
| 985 | or both incomplete.
|
|---|
| 986 |
|
|---|
| 987 | `<'
|
|---|
| 988 | The files differ and only the first file contains the line.
|
|---|
| 989 |
|
|---|
| 990 | `>'
|
|---|
| 991 | The files differ and only the second file contains the line.
|
|---|
| 992 |
|
|---|
| 993 | `('
|
|---|
| 994 | Only the first file contains the line, but the difference is
|
|---|
| 995 | ignored.
|
|---|
| 996 |
|
|---|
| 997 | `)'
|
|---|
| 998 | Only the second file contains the line, but the difference is
|
|---|
| 999 | ignored.
|
|---|
| 1000 |
|
|---|
| 1001 | `\'
|
|---|
| 1002 | The corresponding lines differ, and only the first line is
|
|---|
| 1003 | incomplete.
|
|---|
| 1004 |
|
|---|
| 1005 | `/'
|
|---|
| 1006 | The corresponding lines differ, and only the second line is
|
|---|
| 1007 | incomplete.
|
|---|
| 1008 |
|
|---|
| 1009 | Normally, an output line is incomplete if and only if the lines that
|
|---|
| 1010 | it contains are incomplete; *Note Incomplete Lines::. However, when an
|
|---|
| 1011 | output line represents two differing lines, one might be incomplete
|
|---|
| 1012 | while the other is not. In this case, the output line is complete, but
|
|---|
| 1013 | its the gutter is marked `\' if the first line is incomplete, `/' if
|
|---|
| 1014 | the second line is.
|
|---|
| 1015 |
|
|---|
| 1016 | Side by side format is sometimes easiest to read, but it has
|
|---|
| 1017 | limitations. It generates much wider output than usual, and truncates
|
|---|
| 1018 | lines that are too long to fit. Also, it relies on lining up output
|
|---|
| 1019 | more heavily than usual, so its output looks particularly bad if you
|
|---|
| 1020 | use varying width fonts, nonstandard tab stops, or nonprinting
|
|---|
| 1021 | characters.
|
|---|
| 1022 |
|
|---|
| 1023 | You can use the `sdiff' command to interactively merge side by side
|
|---|
| 1024 | differences. *Note Interactive Merging::, for more information on
|
|---|
| 1025 | merging files.
|
|---|
| 1026 |
|
|---|
| 1027 | * Menu:
|
|---|
| 1028 |
|
|---|
| 1029 | * Side by Side Format:: Controlling side by side output format.
|
|---|
| 1030 | * Example Side by Side:: Sample side by side output.
|
|---|
| 1031 |
|
|---|
| 1032 |
|
|---|
| 1033 | File: diff.info, Node: Side by Side Format, Next: Example Side by Side, Up: Side by Side
|
|---|
| 1034 |
|
|---|
| 1035 | Controlling Side by Side Format
|
|---|
| 1036 | -------------------------------
|
|---|
| 1037 |
|
|---|
| 1038 | The `-y' or `--side-by-side' option selects side by side format.
|
|---|
| 1039 | Because side by side output lines contain two input lines, the output
|
|---|
| 1040 | is wider than usual: normally 130 print columns, which can fit onto a
|
|---|
| 1041 | traditional printer line. You can set the width of the output with the
|
|---|
| 1042 | `-W COLUMNS' or `--width=COLUMNS' option. The output is split into two
|
|---|
| 1043 | halves of equal width, separated by a small gutter to mark differences;
|
|---|
| 1044 | the right half is aligned to a tab stop so that tabs line up. Input
|
|---|
| 1045 | lines that are too long to fit in half of an output line are truncated
|
|---|
| 1046 | for output.
|
|---|
| 1047 |
|
|---|
| 1048 | The `--left-column' option prints only the left column of two common
|
|---|
| 1049 | lines. The `--suppress-common-lines' option suppresses common lines
|
|---|
| 1050 | entirely.
|
|---|
| 1051 |
|
|---|
| 1052 |
|
|---|
| 1053 | File: diff.info, Node: Example Side by Side, Prev: Side by Side Format, Up: Side by Side
|
|---|
| 1054 |
|
|---|
| 1055 | An Example of Side by Side Format
|
|---|
| 1056 | ---------------------------------
|
|---|
| 1057 |
|
|---|
| 1058 | Here is the output of the command `diff -y -W 72 lao tzu' (*note
|
|---|
| 1059 | Sample diff Input::, for the complete contents of the two files).
|
|---|
| 1060 |
|
|---|
| 1061 | The Way that can be told of is n <
|
|---|
| 1062 | The name that can be named is no <
|
|---|
| 1063 | The Nameless is the origin of He The Nameless is the origin of He
|
|---|
| 1064 | The Named is the mother of all t | The named is the mother of all t
|
|---|
| 1065 | >
|
|---|
| 1066 | Therefore let there always be no Therefore let there always be no
|
|---|
| 1067 | so we may see their subtlety, so we may see their subtlety,
|
|---|
| 1068 | And let there always be being, And let there always be being,
|
|---|
| 1069 | so we may see their outcome. so we may see their outcome.
|
|---|
| 1070 | The two are the same, The two are the same,
|
|---|
| 1071 | But after they are produced, But after they are produced,
|
|---|
| 1072 | they have different names. they have different names.
|
|---|
| 1073 | > They both may be called deep and
|
|---|
| 1074 | > Deeper and more profound,
|
|---|
| 1075 | > The door of all subtleties!
|
|---|
| 1076 |
|
|---|
| 1077 |
|
|---|
| 1078 | File: diff.info, Node: Scripts, Next: If-then-else, Prev: Side by Side, Up: Output Formats
|
|---|
| 1079 |
|
|---|
| 1080 | Making Edit Scripts
|
|---|
| 1081 | ===================
|
|---|
| 1082 |
|
|---|
| 1083 | Several output modes produce command scripts for editing FROM-FILE
|
|---|
| 1084 | to produce TO-FILE.
|
|---|
| 1085 |
|
|---|
| 1086 | * Menu:
|
|---|
| 1087 |
|
|---|
| 1088 | * ed Scripts:: Using `diff' to produce commands for `ed'.
|
|---|
| 1089 | * Forward ed:: Making forward `ed' scripts.
|
|---|
| 1090 | * RCS:: A special `diff' output format used by RCS.
|
|---|
| 1091 |
|
|---|
| 1092 |
|
|---|
| 1093 | File: diff.info, Node: ed Scripts, Next: Forward ed, Up: Scripts
|
|---|
| 1094 |
|
|---|
| 1095 | `ed' Scripts
|
|---|
| 1096 | ------------
|
|---|
| 1097 |
|
|---|
| 1098 | `diff' can produce commands that direct the `ed' text editor to
|
|---|
| 1099 | change the first file into the second file. Long ago, this was the
|
|---|
| 1100 | only output mode that was suitable for editing one file into another
|
|---|
| 1101 | automatically; today, with `patch', it is almost obsolete. Use the
|
|---|
| 1102 | `-e' or `--ed' option to select this output format.
|
|---|
| 1103 |
|
|---|
| 1104 | Like the normal format (*note Normal::), this output format does not
|
|---|
| 1105 | show any context; unlike the normal format, it does not include the
|
|---|
| 1106 | information necessary to apply the diff in reverse (to produce the first
|
|---|
| 1107 | file if all you have is the second file and the diff).
|
|---|
| 1108 |
|
|---|
| 1109 | If the file `d' contains the output of `diff -e old new', then the
|
|---|
| 1110 | command `(cat d && echo w) | ed - old' edits `old' to make it a copy of
|
|---|
| 1111 | `new'. More generally, if `d1', `d2', ..., `dN' contain the outputs of
|
|---|
| 1112 | `diff -e old new1', `diff -e new1 new2', ..., `diff -e newN-1 newN',
|
|---|
| 1113 | respectively, then the command `(cat d1 d2 ... dN && echo w) | ed -
|
|---|
| 1114 | old' edits `old' to make it a copy of `newN'.
|
|---|
| 1115 |
|
|---|
| 1116 | * Menu:
|
|---|
| 1117 |
|
|---|
| 1118 | * Detailed ed:: A detailed description of `ed' format.
|
|---|
| 1119 | * Example ed:: A sample `ed' script.
|
|---|
| 1120 |
|
|---|
| 1121 |
|
|---|
| 1122 | File: diff.info, Node: Detailed ed, Next: Example ed, Up: ed Scripts
|
|---|
| 1123 |
|
|---|
| 1124 | Detailed Description of `ed' Format
|
|---|
| 1125 | ...................................
|
|---|
| 1126 |
|
|---|
| 1127 | The `ed' output format consists of one or more hunks of differences.
|
|---|
| 1128 | The changes closest to the ends of the files come first so that
|
|---|
| 1129 | commands that change the number of lines do not affect how `ed'
|
|---|
| 1130 | interprets line numbers in succeeding commands. `ed' format hunks look
|
|---|
| 1131 | like this:
|
|---|
| 1132 |
|
|---|
| 1133 | CHANGE-COMMAND
|
|---|
| 1134 | TO-FILE-LINE
|
|---|
| 1135 | TO-FILE-LINE...
|
|---|
| 1136 | .
|
|---|
| 1137 |
|
|---|
| 1138 | Because `ed' uses a single period on a line to indicate the end of
|
|---|
| 1139 | input, GNU `diff' protects lines of changes that contain a single
|
|---|
| 1140 | period on a line by writing two periods instead, then writing a
|
|---|
| 1141 | subsequent `ed' command to change the two periods into one. The `ed'
|
|---|
| 1142 | format cannot represent an incomplete line, so if the second file ends
|
|---|
| 1143 | in a changed incomplete line, `diff' reports an error and then pretends
|
|---|
| 1144 | that a newline was appended.
|
|---|
| 1145 |
|
|---|
| 1146 | There are three types of change commands. Each consists of a line
|
|---|
| 1147 | number or comma-separated range of lines in the first file and a single
|
|---|
| 1148 | character indicating the kind of change to make. All line numbers are
|
|---|
| 1149 | the original line numbers in the file. The types of change commands
|
|---|
| 1150 | are:
|
|---|
| 1151 |
|
|---|
| 1152 | `La'
|
|---|
| 1153 | Add text from the second file after line L in the first file. For
|
|---|
| 1154 | example, `8a' means to add the following lines after line 8 of file
|
|---|
| 1155 | 1.
|
|---|
| 1156 |
|
|---|
| 1157 | `Rc'
|
|---|
| 1158 | Replace the lines in range R in the first file with the following
|
|---|
| 1159 | lines. Like a combined add and delete, but more compact. For
|
|---|
| 1160 | example, `5,7c' means change lines 5-7 of file 1 to read as the
|
|---|
| 1161 | text file 2.
|
|---|
| 1162 |
|
|---|
| 1163 | `Rd'
|
|---|
| 1164 | Delete the lines in range R from the first file. For example,
|
|---|
| 1165 | `5,7d' means delete lines 5-7 of file 1.
|
|---|
| 1166 |
|
|---|
| 1167 |
|
|---|
| 1168 | File: diff.info, Node: Example ed, Prev: Detailed ed, Up: ed Scripts
|
|---|
| 1169 |
|
|---|
| 1170 | Example `ed' Script
|
|---|
| 1171 | ...................
|
|---|
| 1172 |
|
|---|
| 1173 | Here is the output of `diff -e lao tzu' (*note Sample diff Input::,
|
|---|
| 1174 | for the complete contents of the two files):
|
|---|
| 1175 |
|
|---|
| 1176 | 11a
|
|---|
| 1177 | They both may be called deep and profound.
|
|---|
| 1178 | Deeper and more profound,
|
|---|
| 1179 | The door of all subtleties!
|
|---|
| 1180 | .
|
|---|
| 1181 | 4c
|
|---|
| 1182 | The named is the mother of all things.
|
|---|
| 1183 |
|
|---|
| 1184 | .
|
|---|
| 1185 | 1,2d
|
|---|
| 1186 |
|
|---|
| 1187 |
|
|---|
| 1188 | File: diff.info, Node: Forward ed, Next: RCS, Prev: ed Scripts, Up: Scripts
|
|---|
| 1189 |
|
|---|
| 1190 | Forward `ed' Scripts
|
|---|
| 1191 | --------------------
|
|---|
| 1192 |
|
|---|
| 1193 | `diff' can produce output that is like an `ed' script, but with
|
|---|
| 1194 | hunks in forward (front to back) order. The format of the commands is
|
|---|
| 1195 | also changed slightly: command characters precede the lines they
|
|---|
| 1196 | modify, spaces separate line numbers in ranges, and no attempt is made
|
|---|
| 1197 | to disambiguate hunk lines consisting of a single period. Like `ed'
|
|---|
| 1198 | format, forward `ed' format cannot represent incomplete lines.
|
|---|
| 1199 |
|
|---|
| 1200 | Forward `ed' format is not very useful, because neither `ed' nor
|
|---|
| 1201 | `patch' can apply diffs in this format. It exists mainly for
|
|---|
| 1202 | compatibility with older versions of `diff'. Use the `-f' or
|
|---|
| 1203 | `--forward-ed' option to select it.
|
|---|
| 1204 |
|
|---|
| 1205 |
|
|---|
| 1206 | File: diff.info, Node: RCS, Prev: Forward ed, Up: Scripts
|
|---|
| 1207 |
|
|---|
| 1208 | RCS Scripts
|
|---|
| 1209 | -----------
|
|---|
| 1210 |
|
|---|
| 1211 | The RCS output format is designed specifically for use by the
|
|---|
| 1212 | Revision Control System, which is a set of free programs used for
|
|---|
| 1213 | organizing different versions and systems of files. Use the `-n' or
|
|---|
| 1214 | `--rcs' option to select this output format. It is like the forward
|
|---|
| 1215 | `ed' format (*note Forward ed::), but it can represent arbitrary
|
|---|
| 1216 | changes to the contents of a file because it avoids the forward `ed'
|
|---|
| 1217 | format's problems with lines consisting of a single period and with
|
|---|
| 1218 | incomplete lines. Instead of ending text sections with a line
|
|---|
| 1219 | consisting of a single period, each command specifies the number of
|
|---|
| 1220 | lines it affects; a combination of the `a' and `d' commands are used
|
|---|
| 1221 | instead of `c'. Also, if the second file ends in a changed incomplete
|
|---|
| 1222 | line, then the output also ends in an incomplete line.
|
|---|
| 1223 |
|
|---|
| 1224 | Here is the output of `diff -n lao tzu' (*note Sample diff Input::,
|
|---|
| 1225 | for the complete contents of the two files):
|
|---|
| 1226 |
|
|---|
| 1227 | d1 2
|
|---|
| 1228 | d4 1
|
|---|
| 1229 | a4 2
|
|---|
| 1230 | The named is the mother of all things.
|
|---|
| 1231 |
|
|---|
| 1232 | a11 3
|
|---|
| 1233 | They both may be called deep and profound.
|
|---|
| 1234 | Deeper and more profound,
|
|---|
| 1235 | The door of all subtleties!
|
|---|
| 1236 |
|
|---|
| 1237 |
|
|---|
| 1238 | File: diff.info, Node: If-then-else, Prev: Scripts, Up: Output Formats
|
|---|
| 1239 |
|
|---|
| 1240 | Merging Files with If-then-else
|
|---|
| 1241 | ===============================
|
|---|
| 1242 |
|
|---|
| 1243 | You can use `diff' to merge two files of C source code. The output
|
|---|
| 1244 | of `diff' in this format contains all the lines of both files. Lines
|
|---|
| 1245 | common to both files are output just once; the differing parts are
|
|---|
| 1246 | separated by the C preprocessor directives `#ifdef NAME' or `#ifndef
|
|---|
| 1247 | NAME', `#else', and `#endif'. When compiling the output, you select
|
|---|
| 1248 | which version to use by either defining or leaving undefined the macro
|
|---|
| 1249 | NAME.
|
|---|
| 1250 |
|
|---|
| 1251 | To merge two files, use `diff' with the `-D NAME' or `--ifdef=NAME'
|
|---|
| 1252 | option. The argument NAME is the C preprocessor identifier to use in
|
|---|
| 1253 | the `#ifdef' and `#ifndef' directives.
|
|---|
| 1254 |
|
|---|
| 1255 | For example, if you change an instance of `wait (&s)' to `waitpid
|
|---|
| 1256 | (-1, &s, 0)' and then merge the old and new files with the
|
|---|
| 1257 | `--ifdef=HAVE_WAITPID' option, then the affected part of your code
|
|---|
| 1258 | might look like this:
|
|---|
| 1259 |
|
|---|
| 1260 | do {
|
|---|
| 1261 | #ifndef HAVE_WAITPID
|
|---|
| 1262 | if ((w = wait (&s)) < 0 && errno != EINTR)
|
|---|
| 1263 | #else /* HAVE_WAITPID */
|
|---|
| 1264 | if ((w = waitpid (-1, &s, 0)) < 0 && errno != EINTR)
|
|---|
| 1265 | #endif /* HAVE_WAITPID */
|
|---|
| 1266 | return w;
|
|---|
| 1267 | } while (w != child);
|
|---|
| 1268 |
|
|---|
| 1269 | You can specify formats for languages other than C by using line
|
|---|
| 1270 | group formats and line formats, as described in the next sections.
|
|---|
| 1271 |
|
|---|
| 1272 | * Menu:
|
|---|
| 1273 |
|
|---|
| 1274 | * Line Group Formats:: Formats for general if-then-else line groups.
|
|---|
| 1275 | * Line Formats:: Formats for each line in a line group.
|
|---|
| 1276 | * Detailed If-then-else:: A detailed description of if-then-else format.
|
|---|
| 1277 | * Example If-then-else:: Sample if-then-else format output.
|
|---|
| 1278 |
|
|---|
| 1279 |
|
|---|
| 1280 | File: diff.info, Node: Line Group Formats, Next: Line Formats, Up: If-then-else
|
|---|
| 1281 |
|
|---|
| 1282 | Line Group Formats
|
|---|
| 1283 | ------------------
|
|---|
| 1284 |
|
|---|
| 1285 | Line group formats let you specify formats suitable for many
|
|---|
| 1286 | applications that allow if-then-else input, including programming
|
|---|
| 1287 | languages and text formatting languages. A line group format specifies
|
|---|
| 1288 | the output format for a contiguous group of similar lines.
|
|---|
| 1289 |
|
|---|
| 1290 | For example, the following command compares the TeX files `old' and
|
|---|
| 1291 | `new', and outputs a merged file in which old regions are surrounded by
|
|---|
| 1292 | `\begin{em}'-`\end{em}' lines, and new regions are surrounded by
|
|---|
| 1293 | `\begin{bf}'-`\end{bf}' lines.
|
|---|
| 1294 |
|
|---|
| 1295 | diff \
|
|---|
| 1296 | --old-group-format='\begin{em}
|
|---|
| 1297 | %<\end{em}
|
|---|
| 1298 | ' \
|
|---|
| 1299 | --new-group-format='\begin{bf}
|
|---|
| 1300 | %>\end{bf}
|
|---|
| 1301 | ' \
|
|---|
| 1302 | old new
|
|---|
| 1303 |
|
|---|
| 1304 | The following command is equivalent to the above example, but it is a
|
|---|
| 1305 | little more verbose, because it spells out the default line group
|
|---|
| 1306 | formats.
|
|---|
| 1307 |
|
|---|
| 1308 | diff \
|
|---|
| 1309 | --old-group-format='\begin{em}
|
|---|
| 1310 | %<\end{em}
|
|---|
| 1311 | ' \
|
|---|
| 1312 | --new-group-format='\begin{bf}
|
|---|
| 1313 | %>\end{bf}
|
|---|
| 1314 | ' \
|
|---|
| 1315 | --unchanged-group-format='%=' \
|
|---|
| 1316 | --changed-group-format='\begin{em}
|
|---|
| 1317 | %<\end{em}
|
|---|
| 1318 | \begin{bf}
|
|---|
| 1319 | %>\end{bf}
|
|---|
| 1320 | ' \
|
|---|
| 1321 | old new
|
|---|
| 1322 |
|
|---|
| 1323 | Here is a more advanced example, which outputs a diff listing with
|
|---|
| 1324 | headers containing line numbers in a "plain English" style.
|
|---|
| 1325 |
|
|---|
| 1326 | diff \
|
|---|
| 1327 | --unchanged-group-format='' \
|
|---|
| 1328 | --old-group-format='-------- %dn line%(n=1?:s) deleted at %df:
|
|---|
| 1329 | %<' \
|
|---|
| 1330 | --new-group-format='-------- %dN line%(N=1?:s) added after %de:
|
|---|
| 1331 | %>' \
|
|---|
| 1332 | --changed-group-format='-------- %dn line%(n=1?:s) changed at %df:
|
|---|
| 1333 | %<-------- to:
|
|---|
| 1334 | %>' \
|
|---|
| 1335 | old new
|
|---|
| 1336 |
|
|---|
| 1337 | To specify a line group format, use `diff' with one of the options
|
|---|
| 1338 | listed below. You can specify up to four line group formats, one for
|
|---|
| 1339 | each kind of line group. You should quote FORMAT, because it typically
|
|---|
| 1340 | contains shell metacharacters.
|
|---|
| 1341 |
|
|---|
| 1342 | `--old-group-format=FORMAT'
|
|---|
| 1343 | These line groups are hunks containing only lines from the first
|
|---|
| 1344 | file. The default old group format is the same as the changed
|
|---|
| 1345 | group format if it is specified; otherwise it is a format that
|
|---|
| 1346 | outputs the line group as-is.
|
|---|
| 1347 |
|
|---|
| 1348 | `--new-group-format=FORMAT'
|
|---|
| 1349 | These line groups are hunks containing only lines from the second
|
|---|
| 1350 | file. The default new group format is same as the changed group
|
|---|
| 1351 | format if it is specified; otherwise it is a format that outputs
|
|---|
| 1352 | the line group as-is.
|
|---|
| 1353 |
|
|---|
| 1354 | `--changed-group-format=FORMAT'
|
|---|
|
|---|