This is Info file diff.info, produced by Makeinfo-1.55 from the input file ./diff.texi. This file documents the the GNU `diff', `diff3', `sdiff', and `cmp' commands for showing the differences between text files and the `patch' command for using their output to update files. Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Foundation. File: diff.info, Node: Making Patches, Next: Invoking cmp, Prev: Merging with patch, Up: Top Tips for Making Patch Distributions *********************************** Here are some things you should keep in mind if you are going to distribute patches for updating a software package. Make sure you have specified the file names correctly, either in a context diff header or with an `Index:' line. If you are patching files in a subdirectory, be sure to tell the patch user to specify a `-p' or `--strip' option as needed. Take care to not send out reversed patches, since these make people wonder whether they have already applied the patch. To save people from partially applying a patch before other patches that should have gone before it, you can make the first patch in the patch file update a file with a name like `patchlevel.h' or `version.c', which contains a patch level or version number. If the input file contains the wrong version number, `patch' will complain immediately. An even clearer way to prevent this problem is to put a `Prereq:' line before the patch. If the leading text in the patch file contains a line that starts with `Prereq:', `patch' takes the next word from that line (normally a version number) and checks whether the next input file contains that word, preceded and followed by either white space or a newline. If not, `patch' prompts you for confirmation before proceeding. This makes it difficult to accidentally apply patches in the wrong order. Since `patch' does not handle incomplete lines properly, make sure that all the source files in your program end with a newline whenever you release a version. To create a patch that changes an older version of a package into a newer version, first make a copy of the older version in a scratch directory. Typically you do that by unpacking a `tar' or `shar' archive of the older version. You might be able to reduce the size of the patch by renaming or removing some files before making the patch. If the older version of the package contains any files that the newer version does not, or if any files have been renamed between the two versions, make a list of `rm' and `mv' commands for the user to execute in the old version directory before applying the patch. Then run those commands yourself in the scratch directory. If there are any files that you don't need to include in the patch because they can easily be rebuilt from other files (for example, `TAGS' and output from `yacc' and `makeinfo'), replace the versions in the scratch directory with the newer versions, using `rm' and `ln' or `cp'. Now you can create the patch. The de-facto standard `diff' format for patch distributions is context format with two lines of context, produced by giving `diff' the `-C 2' option. Do not use less than two lines of context, because `patch' typically needs at least two lines for proper operation. Give `diff' the `-P' option in case the newer version of the package contains any files that the older one does not. Make sure to specify the scratch directory first and the newer directory second. Add to the top of the patch a note telling the user any `rm' and `mv' commands to run before applying the patch. Then you can remove the scratch directory. File: diff.info, Node: Invoking cmp, Next: Invoking diff, Prev: Making Patches, Up: Top Invoking `cmp' ************** The `cmp' command compares two files, and if they differ, tells the first byte and line number where they differ. Its arguments are as follows: cmp OPTIONS... FROM-FILE [TO-FILE] The file name `-' is always the standard input. `cmp' also uses the standard input if one file name is omitted. An exit status of 0 means no differences were found, 1 means some differences were found, and 2 means trouble. * Menu: * cmp Options:: Summary of options to `cmp'. File: diff.info, Node: cmp Options, Up: Invoking cmp Options to `cmp' ================ Below is a summary of all of the options that GNU `cmp' accepts. Most options have two equivalent names, one of which is a single letter preceded by `-', and the other of which is a long name preceded by `--'. Multiple single letter options (unless they take an argument) can be combined into a single command line word: `-cl' is equivalent to `-c -l'. Print the differing characters. Display control characters as a `^' followed by a letter of the alphabet and precede characters that have the high bit set with `M-' (which stands for "meta"). `--ignore-initial=BYTES' Ignore any differences in the the first BYTES bytes of the input files. Treat files with fewer than BYTES bytes as if they are empty. Print the (decimal) offsets and (octal) values of all differing bytes. `--print-chars' Print the differing characters. Display control characters as a `^' followed by a letter of the alphabet and precede characters that have the high bit set with `M-' (which stands for "meta"). `--quiet' `--silent' Do not print anything; only return an exit status indicating whether the files differ. `--verbose' Print the (decimal) offsets and (octal) values of all differing bytes. `--version' Output the version number of `cmp'. File: diff.info, Node: Invoking diff, Next: Invoking diff3, Prev: Invoking cmp, Up: Top Invoking `diff' *************** The format for running the `diff' command is: diff OPTIONS... FROM-FILE TO-FILE In the simplest case, `diff' compares the contents of the two files FROM-FILE and TO-FILE. A file name of `-' stands for text read from the standard input. As a special case, `diff - -' compares a copy of standard input to itself. If FROM-FILE is a directory and TO-FILE is not, `diff' compares the file in FROM-FILE whose file name is that of TO-FILE, and vice versa. The non-directory file must not be `-'. If both FROM-FILE and TO-FILE are directories, `diff' compares corresponding files in both directories, in alphabetical order; this comparison is not recursive unless the `-r' or `--recursive' option is given. `diff' never compares the actual contents of a directory as if it were a file. The file that is fully specified may not be standard input, because standard input is nameless and the notion of "file with the same name" does not apply. `diff' options begin with `-', so normally FROM-FILE and TO-FILE may not begin with `-'. However, `--' as an argument by itself treats the remaining arguments as file names even if they begin with `-'. An exit status of 0 means no differences were found, 1 means some differences were found, and 2 means trouble. * Menu: * diff Options:: Summary of options to `diff'. File: diff.info, Node: diff Options, Up: Invoking diff Options to `diff' ================= Below is a summary of all of the options that GNU `diff' accepts. Most options have two equivalent names, one of which is a single letter preceded by `-', and the other of which is a long name preceded by `--'. Multiple single letter options (unless they take an argument) can be combined into a single command line word: `-ac' is equivalent to `-a -c'. Long named options can be abbreviated to any unique prefix of their name. Brackets ([ and ]) indicate that an option takes an optional argument. `-LINES' Show LINES (an integer) lines of context. This option does not specify an output format by itself; it has no effect unless it is combined with `-c' (*note Context Format::.) or `-u' (*note Unified Format::.). This option is obsolete. For proper operation, `patch' typically needs at least two lines of context. Treat all files as text and compare them line-by-line, even if they do not seem to be text. *Note Binary::. Ignore changes in amount of white space. *Note White Space::. Ignore changes that just insert or delete blank lines. *Note Blank Lines::. `--binary' Read and write data in binary mode. *Note Binary::. `--brief' Report only whether the files differ, not the details of the differences. *Note Brief::. Use the context output format. *Note Context Format::. `-C LINES' `--context[=LINES]' Use the context output format, showing LINES (an integer) lines of context, or three if LINES is not given. *Note Context Format::. For proper operation, `patch' typically needs at least two lines of context. `--changed-group-format=FORMAT' Use FORMAT to output a line group containing differing lines from both files in if-then-else format. *Note Line Group Formats::. Change the algorithm perhaps find a smaller set of changes. This makes `diff' slower (sometimes much slower). *Note diff Performance::. `-D NAME' Make merged `#ifdef' format output, conditional on the preprocessor macro NAME. *Note If-then-else::. `--ed' Make output that is a valid `ed' script. *Note ed Scripts::. `--exclude=PATTERN' When comparing directories, ignore files and subdirectories whose basenames match PATTERN. *Note Comparing Directories::. `--exclude-from=FILE' When comparing directories, ignore files and subdirectories whose basenames match any pattern contained in FILE. *Note Comparing Directories::. `--expand-tabs' Expand tabs to spaces in the output, to preserve the alignment of tabs in the input files. *Note Tabs::. Make output that looks vaguely like an `ed' script but has changes in the order they appear in the file. *Note Forward ed::. `-F REGEXP' In context and unified format, for each hunk of differences, show some of the last preceding line that matches REGEXP. *Note Specified Headings::. `--forward-ed' Make output that looks vaguely like an `ed' script but has changes in the order they appear in the file. *Note Forward ed::. This option currently has no effect; it is present for Unix compatibility. Use heuristics to speed handling of large files that have numerous scattered small changes. *Note diff Performance::. `--horizon-lines=LINES' Do not discard the last LINES lines of the common prefix and the first LINES lines of the common suffix. *Note diff Performance::. Ignore changes in case; consider upper- and lower-case letters equivalent. *Note Case Folding::. `-I REGEXP' Ignore changes that just insert or delete lines that match REGEXP. *Note Specified Folding::. `--ifdef=NAME' Make merged if-then-else output using NAME. *Note If-then-else::. `--ignore-all-space' Ignore white space when comparing lines. *Note White Space::. `--ignore-blank-lines' Ignore changes that just insert or delete blank lines. *Note Blank Lines::. `--ignore-case' Ignore changes in case; consider upper- and lower-case to be the same. *Note Case Folding::. `--ignore-matching-lines=REGEXP' Ignore changes that just insert or delete lines that match REGEXP. *Note Specified Folding::. `--ignore-space-change' Ignore changes in amount of white space. *Note White Space::. `--initial-tab' Output a tab rather than a space before the text of a line in normal or context format. This causes the alignment of tabs in the line to look normal. *Note Tabs::. Pass the output through `pr' to paginate it. *Note Pagination::. `-L LABEL' Use LABEL instead of the file name in the context format (*note Context Format::.) and unified format (*note Unified Format::.) headers. *Note RCS::. `--label=LABEL' Use LABEL instead of the file name in the context format (*note Context Format::.) and unified format (*note Unified Format::.) headers. `--left-column' Print only the left column of two common lines in side by side format. *Note Side by Side Format::. `--line-format=FORMAT' Use FORMAT to output all input lines in if-then-else format. *Note Line Formats::. `--minimal' Change the algorithm to perhaps find a smaller set of changes. This makes `diff' slower (sometimes much slower). *Note diff Performance::. Output RCS-format diffs; like `-f' except that each command specifies the number of lines affected. *Note RCS::. `--new-file' In directory comparison, if a file is found in only one directory, treat it as present but empty in the other directory. *Note Comparing Directories::. `--new-group-format=FORMAT' Use FORMAT to output a group of lines taken from just the second file in if-then-else format. *Note Line Group Formats::. `--new-line-format=FORMAT' Use FORMAT to output a line taken from just the second file in if-then-else format. *Note Line Formats::. `--old-group-format=FORMAT' Use FORMAT to output a group of lines taken from just the first file in if-then-else format. *Note Line Group Formats::. `--old-line-format=FORMAT' Use FORMAT to output a line taken from just the first file in if-then-else format. *Note Line Formats::. Show which C function each change is in. *Note C Function Headings::. When comparing directories, if a file appears only in the second directory of the two, treat it as present but empty in the other. *Note Comparing Directories::. `--paginate' Pass the output through `pr' to paginate it. *Note Pagination::. Report only whether the files differ, not the details of the differences. *Note Brief::. When comparing directories, recursively compare any subdirectories found. *Note Comparing Directories::. `--rcs' Output RCS-format diffs; like `-f' except that each command specifies the number of lines affected. *Note RCS::. `--recursive' When comparing directories, recursively compare any subdirectories found. *Note Comparing Directories::. `--report-identical-files' Report when two files are the same. *Note Comparing Directories::. Report when two files are the same. *Note Comparing Directories::. `-S FILE' When comparing directories, start with the file FILE. This is used for resuming an aborted comparison. *Note Comparing Directories::. `--sdiff-merge-assist' Print extra information to help `sdiff'. `sdiff' uses this option when it runs `diff'. This option is not intended for users to use directly. `--show-c-function' Show which C function each change is in. *Note C Function Headings::. `--show-function-line=REGEXP' In context and unified format, for each hunk of differences, show some of the last preceding line that matches REGEXP. *Note Specified Headings::. `--side-by-side' Use the side by side output format. *Note Side by Side Format::. `--speed-large-files' Use heuristics to speed handling of large files that have numerous scattered small changes. *Note diff Performance::. `--starting-file=FILE' When comparing directories, start with the file FILE. This is used for resuming an aborted comparison. *Note Comparing Directories::. `--suppress-common-lines' Do not print common lines in side by side format. *Note Side by Side Format::. Expand tabs to spaces in the output, to preserve the alignment of tabs in the input files. *Note Tabs::. Output a tab rather than a space before the text of a line in normal or context format. This causes the alignment of tabs in the line to look normal. *Note Tabs::. `--text' Treat all files as text and compare them line-by-line, even if they do not appear to be text. *Note Binary::. Use the unified output format. *Note Unified Format::. `--unchanged-group-format=FORMAT' Use FORMAT to output a group of common lines taken from both files in if-then-else format. *Note Line Group Formats::. `--unchanged-line-format=FORMAT' Use FORMAT to output a line common to both files in if-then-else format. *Note Line Formats::. `--unidirectional-new-file' When comparing directories, if a file appears only in the second directory of the two, treat it as present but empty in the other. *Note Comparing Directories::. `-U LINES' `--unified[=LINES]' Use the unified output format, showing LINES (an integer) lines of context, or three if LINES is not given. *Note Unified Format::. For proper operation, `patch' typically needs at least two lines of context. `--version' Output the version number of `diff'. Ignore white space when comparing lines. *Note White Space::. `-W COLUMNS' `--width=COLUMNS' Use an output width of COLUMNS in side by side format. *Note Side by Side Format::. `-x PATTERN' When comparing directories, ignore files and subdirectories whose basenames match PATTERN. *Note Comparing Directories::. `-X FILE' When comparing directories, ignore files and subdirectories whose basenames match any pattern contained in FILE. *Note Comparing Directories::. Use the side by side output format. *Note Side by Side Format::. File: diff.info, Node: Invoking diff3, Next: Invoking patch, Prev: Invoking diff, Up: Top Invoking `diff3' **************** The `diff3' command compares three files and outputs descriptions of their differences. Its arguments are as follows: diff3 OPTIONS... MINE OLDER YOURS The files to compare are MINE, OLDER, and YOURS. At most one of these three file names may be `-', which tells `diff3' to read the standard input for that file. An exit status of 0 means `diff3' was successful, 1 means some conflicts were found, and 2 means trouble. * Menu: * diff3 Options:: Summary of options to `diff3'. File: diff.info, Node: diff3 Options, Up: Invoking diff3 Options to `diff3' ================== Below is a summary of all of the options that GNU `diff3' accepts. Multiple single letter options (unless they take an argument) can be combined into a single command line argument. Treat all files as text and compare them line-by-line, even if they do not appear to be text. *Note Binary::. Incorporate all changes from OLDER to YOURS into MINE, surrounding all conflicts with bracket lines. *Note Marking Conflicts::. Generate an `ed' script that incorporates all the changes from OLDER to YOURS into MINE. *Note Which Changes::. Like `-e', except bracket lines from overlapping changes' first and third files. *Note Marking Conflicts::. With `-e', an overlapping change looks like this: <<<<<<< MINE lines from MINE ======= lines from YOURS >>>>>>> YOURS `--ed' Generate an `ed' script that incorporates all the changes from OLDER to YOURS into MINE. *Note Which Changes::. `--easy-only' Like `-e', except output only the nonoverlapping changes. *Note Which Changes::. Generate `w' and `q' commands at the end of the `ed' script for System V compatibility. This option must be combined with one of the `-AeExX3' options, and may not be combined with `-m'. *Note Saving the Changed File::. `--initial-tab' Output a tab rather than two spaces before the text of a line in normal format. This causes the alignment of tabs in the line to look normal. *Note Tabs::. `-L LABEL' `--label=LABEL' Use the label LABEL for the brackets output by the `-A', `-E' and `-X' options. This option may be given up to three times, one for each input file. The default labels are the names of the input files. Thus `diff3 -L X -L Y -L Z -m A B C' acts like `diff3 -m A B C', except that the output looks like it came from files named `X', `Y' and `Z' rather than from files named `A', `B' and `C'. *Note Marking Conflicts::. `--merge' Apply the edit script to the first file and send the result to standard output. Unlike piping the output from `diff3' to `ed', this works even for binary files and incomplete lines. `-A' is assumed if no edit script option is specified. *Note Bypassing ed::. `--overlap-only' Like `-e', except output only the overlapping changes. *Note Which Changes::. `--show-all' Incorporate all unmerged changes from OLDER to YOURS into MINE, surrounding all overlapping changes with bracket lines. *Note Marking Conflicts::. `--show-overlap' Like `-e', except bracket lines from overlapping changes' first and third files. *Note Marking Conflicts::. Output a tab rather than two spaces before the text of a line in normal format. This causes the alignment of tabs in the line to look normal. *Note Tabs::. `--text' Treat all files as text and compare them line-by-line, even if they do not appear to be text. *Note Binary::. `--version' Output the version number of `diff3'. Like `-e', except output only the overlapping changes. *Note Which Changes::. Like `-E', except output only the overlapping changes. In other words, like `-x', except bracket changes as in `-E'. *Note Marking Conflicts::. Like `-e', except output only the nonoverlapping changes. *Note Which Changes::. File: diff.info, Node: Invoking patch, Next: Invoking sdiff, Prev: Invoking diff3, Up: Top Invoking `patch' **************** Normally `patch' is invoked like this: patch g \ No newline at end of file (The exact message may differ in non-English locales.) `diff -n F G' outputs the following without a trailing newline: d1 1 a1 1 g `diff -e F G' reports two errors and outputs the following: 1c g . File: diff.info, Node: Projects, Next: Concept Index, Prev: Incomplete Lines, Up: Top Future Projects *************** Here are some ideas for improving GNU `diff' and `patch'. The GNU project has identified some improvements as potential programming projects for volunteers. You can also help by reporting any bugs that you find. If you are a programmer and would like to contribute something to the GNU project, please consider volunteering for one of these projects. If you are seriously contemplating work, please write to `gnu@prep.ai.mit.edu' to coordinate with other volunteers. * Menu: * Shortcomings:: Suggested projects for improvements. * Bugs:: Reporting bugs. File: diff.info, Node: Shortcomings, Next: Bugs, Up: Projects Suggested Projects for Improving GNU `diff' and `patch' ======================================================= One should be able to use GNU `diff' to generate a patch from any pair of directory trees, and given the patch and a copy of one such tree, use `patch' to generate a faithful copy of the other. Unfortunately, some changes to directory trees cannot be expressed using current patch formats; also, `patch' does not handle some of the existing formats. These shortcomings motivate the following suggested projects. * Menu: * Changing Structure:: Handling changes to the directory structure. * Special Files:: Handling symbolic links, device special files, etc. * Unusual File Names:: Handling file names that contain unusual characters. * Arbitrary Limits:: Patching non-text files. * Large Files:: Handling files that do not fit in memory. * Ignoring Changes:: Ignoring certain changes while showing others. File: diff.info, Node: Changing Structure, Next: Special Files, Up: Shortcomings Handling Changes to the Directory Structure ------------------------------------------- `diff' and `patch' do not handle some changes to directory structure. For example, suppose one directory tree contains a directory named `D' with some subsidiary files, and another contains a file with the same name `D'. `diff -r' does not output enough information for `patch' to transform the the directory subtree into the file. There should be a way to specify that a file has been deleted without having to include its entire contents in the patch file. There should also be a way to tell `patch' that a file was renamed, even if there is no way for `diff' to generate such information. These problems can be fixed by extending the `diff' output format to represent changes in directory structure, and extending `patch' to understand these extensions. File: diff.info, Node: Special Files, Next: Unusual File Names, Prev: Changing Structure, Up: Shortcomings Files that are Neither Directories Nor Regular Files ---------------------------------------------------- Some files are neither directories nor regular files: they are unusual files like symbolic links, device special files, named pipes, and sockets. Currently, `diff' treats symbolic links like regular files; it treats other special files like regular files if they are specified at the top level, but simply reports their presence when comparing directories. This means that `patch' cannot represent changes to such files. For example, if you change which file a symbolic link points to, `diff' outputs the difference between the two files, instead of the change to the symbolic link. `diff' should optionally report changes to special files specially, and `patch' should be extended to understand these extensions. File: diff.info, Node: Unusual File Names, Next: Arbitrary Limits, Prev: Special Files, Up: Shortcomings File Names that Contain Unusual Characters ------------------------------------------ When a file name contains an unusual character like a newline or white space, `diff -r' generates a patch that `patch' cannot parse. The problem is with format of `diff' output, not just with `patch', because with odd enough file names one can cause `diff' to generate a patch that is syntactically correct but patches the wrong files. The format of `diff' output should be extended to handle all possible file names. File: diff.info, Node: Arbitrary Limits, Next: Large Files, Prev: Unusual File Names, Up: Shortcomings Arbitrary Limits ---------------- GNU `diff' can analyze files with arbitrarily long lines and files that end in incomplete lines. However, `patch' cannot patch such files. The `patch' internal limits on line lengths should be removed, and `patch' should be extended to parse `diff' reports of incomplete lines. File: diff.info, Node: Large Files, Next: Ignoring Changes, Prev: Arbitrary Limits, Up: Shortcomings Handling Files that Do Not Fit in Memory ---------------------------------------- `diff' operates by reading both files into memory. This method fails if the files are too large, and `diff' should have a fallback. One way to do this is to scan the files sequentially to compute hash codes of the lines and put the lines in equivalence classes based only on hash code. Then compare the files normally. This does produce some false matches. Then scan the two files sequentially again, checking each match to see whether it is real. When a match is not real, mark both the "matching" lines as changed. Then build an edit script as usual. The output routines would have to be changed to scan the files sequentially looking for the text to print. File: diff.info, Node: Ignoring Changes, Prev: Large Files, Up: Shortcomings Ignoring Certain Changes ------------------------ It would be nice to have a feature for specifying two strings, one in FROM-FILE and one in TO-FILE, which should be considered to match. Thus, if the two strings are `foo' and `bar', then if two lines differ only in that `foo' in file 1 corresponds to `bar' in file 2, the lines are treated as identical. It is not clear how general this feature can or should be, or what syntax should be used for it. File: diff.info, Node: Bugs, Prev: Shortcomings, Up: Projects Reporting Bugs ============== If you think you have found a bug in GNU `cmp', `diff', `diff3', `sdiff', or `patch', please report it by electronic mail to `bug-gnu-utils@prep.ai.mit.edu'. Send as precise a description of the problem as you can, including sample input files that produce the bug, if applicable. Because Larry Wall has not released a new version of `patch' since mid 1988 and the GNU version of `patch' has been changed since then, please send bug reports for `patch' by electronic mail to both `bug-gnu-utils@prep.ai.mit.edu' and `lwall@netlabs.com'.