/usr/share/doc/diffutils-doc/Merging-with-patch.html is in diffutils-doc 1:3.5-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This manual is for GNU Diffutils
(version 3.5, 4 August 2016),
and documents the GNU diff, diff3,
sdiff, and cmp commands for showing the
differences between files and the GNU patch command for
using their output to update files.
Copyright (C) 1992-1994, 1998, 2001-2002, 2004, 2006, 2009-2016 Free
Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled
"GNU Free Documentation License." -->
<!-- Created by GNU Texinfo 6.3, http://www.gnu.org/software/texinfo/ -->
<head>
<title>Comparing and Merging Files: Merging with patch</title>
<meta name="description" content="Comparing and Merging Files: Merging with patch">
<meta name="keywords" content="Comparing and Merging Files: Merging with patch">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="Index.html#Index" rel="index" title="Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="index.html#Top" rel="up" title="Top">
<link href="Making-Patches.html#Making-Patches" rel="next" title="Making Patches">
<link href="Interactive-Merging.html#Merge-Commands" rel="prev" title="Merge Commands">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en">
<a name="Merging-with-patch"></a>
<div class="header">
<p>
Next: <a href="Making-Patches.html#Making-Patches" accesskey="n" rel="next">Making Patches</a>, Previous: <a href="Interactive-Merging.html#Interactive-Merging" accesskey="p" rel="prev">Interactive Merging</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Merging-with-patch-1"></a>
<h2 class="chapter">10 Merging with <code>patch</code></h2>
<p><code>patch</code> takes comparison output produced by <code>diff</code> and applies
the differences to a copy of the original file, producing a patched
version. With <code>patch</code>, you can distribute just the changes to a
set of files instead of distributing the entire file set; your
correspondents can apply <code>patch</code> to update their copy of the files
with your changes. <code>patch</code> automatically determines the diff
format, skips any leading or trailing headers, and uses the headers to
determine which file to patch. This lets your correspondents feed a
mail message containing a difference listing directly to
<code>patch</code>.
</p>
<p><code>patch</code> detects and warns about common problems like forward
patches. It saves any patches that it could not apply. It can also maintain a
<code>patchlevel.h</code> file to ensure that your correspondents apply
diffs in the proper order.
</p>
<p><code>patch</code> accepts a series of diffs in its standard input, usually
separated by headers that specify which file to patch. It applies
<code>diff</code> hunks (see <a href="Comparison.html#Hunks">Hunks</a>) one by one. If a hunk does not
exactly match the original file, <code>patch</code> uses heuristics to try to
patch the file as well as it can. If no approximate match can be found,
<code>patch</code> rejects the hunk and skips to the next hunk. <code>patch</code>
normally replaces each file <var>f</var> with its new version, putting reject
hunks (if any) into ‘<samp><var>f</var>.rej</samp>’.
</p>
<p>See <a href="Invoking-patch.html#Invoking-patch">Invoking patch</a>, for detailed information on the options to
<code>patch</code>.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#patch-Input" accesskey="1">patch Input</a>:</td><td> </td><td align="left" valign="top">Selecting the type of <code>patch</code> input.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Revision-Control" accesskey="2">Revision Control</a>:</td><td> </td><td align="left" valign="top">Getting files from <acronym>RCS</acronym>, <acronym>SCCS</acronym>, etc.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Imperfect" accesskey="3">Imperfect</a>:</td><td> </td><td align="left" valign="top">Dealing with imperfect patches.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Creating-and-Removing" accesskey="4">Creating and Removing</a>:</td><td> </td><td align="left" valign="top">Creating and removing files with a patch.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Patching-Time-Stamps" accesskey="5">Patching Time Stamps</a>:</td><td> </td><td align="left" valign="top">Updating time stamps on patched files.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Multiple-Patches" accesskey="6">Multiple Patches</a>:</td><td> </td><td align="left" valign="top">Handling multiple patches in a file.
</td></tr>
<tr><td align="left" valign="top">• <a href="#patch-Directories" accesskey="7">patch Directories</a>:</td><td> </td><td align="left" valign="top">Changing directory and stripping directories.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Backups" accesskey="8">Backups</a>:</td><td> </td><td align="left" valign="top">Whether backup files are made.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Backup-Names" accesskey="9">Backup Names</a>:</td><td> </td><td align="left" valign="top">Backup file names.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Reject-Names">Reject Names</a>:</td><td> </td><td align="left" valign="top">Reject file names.
</td></tr>
<tr><td align="left" valign="top">• <a href="#patch-Messages">patch Messages</a>:</td><td> </td><td align="left" valign="top">Messages and questions <code>patch</code> can produce.
</td></tr>
<tr><td align="left" valign="top">• <a href="#patch-and-POSIX">patch and POSIX</a>:</td><td> </td><td align="left" valign="top">Conformance to the <acronym>POSIX</acronym> standard.
</td></tr>
<tr><td align="left" valign="top">• <a href="#patch-and-Tradition">patch and Tradition</a>:</td><td> </td><td align="left" valign="top"><acronym>GNU</acronym> versus traditional <code>patch</code>.
</td></tr>
</table>
<hr>
<a name="patch-Input"></a>
<div class="header">
<p>
Next: <a href="#Revision-Control" accesskey="n" rel="next">Revision Control</a>, Up: <a href="#Merging-with-patch" accesskey="u" rel="up">Merging with patch</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Selecting-the-patch-Input-Format"></a>
<h3 class="section">10.1 Selecting the <code>patch</code> Input Format</h3>
<a name="index-patch-input-format"></a>
<p><code>patch</code> normally determines which <code>diff</code> format the patch
file uses by examining its contents. For patch files that contain
particularly confusing leading text, you might need to use one of the
following options to force <code>patch</code> to interpret the patch file as a
certain format of diff. The output formats listed here are the only
ones that <code>patch</code> can understand.
</p>
<dl compact="compact">
<dt><samp>-c</samp></dt>
<dt><samp>--context</samp></dt>
<dd><p>context diff.
</p>
</dd>
<dt><samp>-e</samp></dt>
<dt><samp>--ed</samp></dt>
<dd><p><code>ed</code> script.
</p>
</dd>
<dt><samp>-n</samp></dt>
<dt><samp>--normal</samp></dt>
<dd><p>normal diff.
</p>
</dd>
<dt><samp>-u</samp></dt>
<dt><samp>--unified</samp></dt>
<dd><p>unified diff.
</p></dd>
</dl>
<hr>
<a name="Revision-Control"></a>
<div class="header">
<p>
Next: <a href="#Imperfect" accesskey="n" rel="next">Imperfect</a>, Previous: <a href="#patch-Input" accesskey="p" rel="prev">patch Input</a>, Up: <a href="#Merging-with-patch" accesskey="u" rel="up">Merging with patch</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Revision-Control-1"></a>
<h3 class="section">10.2 Revision Control</h3>
<a name="index-revision-control"></a>
<a name="index-version-control"></a>
<a name="index-RCS"></a>
<a name="index-ClearCase"></a>
<a name="index-SCCS"></a>
<p>If a nonexistent input file is under a revision control system
supported by <code>patch</code>, <code>patch</code> normally asks the user
whether to get (or check out) the file from the revision control
system. Patch currently supports <acronym>RCS</acronym>, ClearCase and
<acronym>SCCS</acronym>. Under <acronym>RCS</acronym> and <acronym>SCCS</acronym>,
<code>patch</code> also asks when the input file is read-only and matches
the default version in the revision control system.
</p>
<a name="index-PATCH_005fGET"></a>
<p>The <samp>--get=<var>num</var></samp> (<samp>-g <var>num</var></samp>) option affects access
to files under supported revision control systems. If <var>num</var> is
positive, <code>patch</code> gets the file without asking the user; if
zero, <code>patch</code> neither asks the user nor gets the file; and if
negative, <code>patch</code> asks the user before getting the file. The
default value of <var>num</var> is given by the value of the
<code>PATCH_GET</code> environment variable if it is set; if not, the default
value is zero if <code>patch</code> is conforming to <acronym>POSIX</acronym>, negative
otherwise. See <a href="#patch-and-POSIX">patch and POSIX</a>.
</p>
<a name="index-VERSION_005fCONTROL"></a>
<p>The choice of revision control system is unaffected by the
<code>VERSION_CONTROL</code> environment variable (see <a href="#Backup-Names">Backup Names</a>).
</p>
<hr>
<a name="Imperfect"></a>
<div class="header">
<p>
Next: <a href="#Creating-and-Removing" accesskey="n" rel="next">Creating and Removing</a>, Previous: <a href="#Revision-Control" accesskey="p" rel="prev">Revision Control</a>, Up: <a href="#Merging-with-patch" accesskey="u" rel="up">Merging with patch</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Applying-Imperfect-Patches"></a>
<h3 class="section">10.3 Applying Imperfect Patches</h3>
<a name="index-imperfect-patch-application"></a>
<p><code>patch</code> tries to skip any leading text in the patch file,
apply the diff, and then skip any trailing text. Thus you can feed a
mail message directly to <code>patch</code>, and it should work. If the
entire diff is indented by a constant amount of white space,
<code>patch</code> automatically ignores the indentation. If a context
diff contains trailing carriage return on each line, <code>patch</code>
automatically ignores the carriage return. If a context diff has been
encapsulated by prepending ‘<samp><span class="nolinebreak">-</span> </samp>’<!-- /@w --> to lines beginning with ‘<samp>-</samp>’
as per <a href="ftp://ftp.isi.edu/in-notes/rfc934.txt">Internet RFC 934</a>,
<code>patch</code> automatically unencapsulates the input.
</p>
<p>However, certain other types of imperfect input require user
intervention or testing.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Changed-White-Space" accesskey="1">Changed White Space</a>:</td><td> </td><td align="left" valign="top">When tabs and spaces don’t match exactly.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Reversed-Patches" accesskey="2">Reversed Patches</a>:</td><td> </td><td align="left" valign="top">Applying reversed patches correctly.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Inexact" accesskey="3">Inexact</a>:</td><td> </td><td align="left" valign="top">Helping <code>patch</code> find close matches.
</td></tr>
<tr><td align="left" valign="top">• <a href="#Dry-Runs" accesskey="4">Dry Runs</a>:</td><td> </td><td align="left" valign="top">Predicting what <code>patch</code> will do.
</td></tr>
</table>
<hr>
<a name="Changed-White-Space"></a>
<div class="header">
<p>
Next: <a href="#Reversed-Patches" accesskey="n" rel="next">Reversed Patches</a>, Up: <a href="#Imperfect" accesskey="u" rel="up">Imperfect</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Applying-Patches-with-Changed-White-Space"></a>
<h4 class="subsection">10.3.1 Applying Patches with Changed White Space</h4>
<a name="index-white-space-in-patches"></a>
<p>Sometimes mailers, editors, or other programs change spaces into tabs,
or vice versa. If this happens to a patch file or an input file, the
files might look the same, but <code>patch</code> will not be able to match
them properly. If this problem occurs, use the <samp>-l</samp> or
<samp>--ignore-white-space</samp> option, which makes <code>patch</code> compare
blank characters (i.e. spaces and tabs) loosely so that any nonempty
sequence of blanks in the patch file matches any nonempty sequence of
blanks in the input files. Non-blank
characters must still match exactly. Each line of the context must
still match a line in the input file.
</p>
<hr>
<a name="Reversed-Patches"></a>
<div class="header">
<p>
Next: <a href="#Inexact" accesskey="n" rel="next">Inexact</a>, Previous: <a href="#Changed-White-Space" accesskey="p" rel="prev">Changed White Space</a>, Up: <a href="#Imperfect" accesskey="u" rel="up">Imperfect</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Applying-Reversed-Patches"></a>
<h4 class="subsection">10.3.2 Applying Reversed Patches</h4>
<a name="index-reversed-patches"></a>
<p>Sometimes people run <code>diff</code> with the new file first instead of
second. This creates a diff that is “reversed”. To apply such
patches, give <code>patch</code> the <samp>--reverse</samp> (<samp>-R</samp>) option.
<code>patch</code> then attempts to swap each hunk around before applying it.
Rejects come out in the swapped format.
</p>
<p>Often <code>patch</code> can guess that the patch is reversed. If the first
hunk of a patch fails, <code>patch</code> reverses the hunk to see if it can
apply it that way. If it can, <code>patch</code> asks you if you want to have
the <samp>-R</samp> option set; if it can’t, <code>patch</code> continues to apply
the patch normally. This method cannot detect a reversed patch if it is
a normal diff and the first command is an append (which should have been
a delete) since appends always succeed, because a null context matches
anywhere. But most patches add or change lines rather than delete them,
so most reversed normal diffs begin with a delete, which fails, and
<code>patch</code> notices.
</p>
<p>If you apply a patch that you have already applied, <code>patch</code> thinks
it is a reversed patch and offers to un-apply the patch. This could be
construed as a feature. If you did this inadvertently and you don’t
want to un-apply the patch, just answer ‘<samp>n</samp>’ to this offer and to
the subsequent “apply anyway” question—or type <kbd>C-c</kbd> to kill the
<code>patch</code> process.
</p>
<hr>
<a name="Inexact"></a>
<div class="header">
<p>
Next: <a href="#Dry-Runs" accesskey="n" rel="next">Dry Runs</a>, Previous: <a href="#Reversed-Patches" accesskey="p" rel="prev">Reversed Patches</a>, Up: <a href="#Imperfect" accesskey="u" rel="up">Imperfect</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Helping-patch-Find-Inexact-Matches"></a>
<h4 class="subsection">10.3.3 Helping <code>patch</code> Find Inexact Matches</h4>
<a name="index-inexact-patches"></a>
<a name="index-fuzz-factor-when-patching"></a>
<p>For context diffs, and to a lesser extent normal diffs, <code>patch</code> can
detect when the line numbers mentioned in the patch are incorrect, and
it attempts to find the correct place to apply each hunk of the patch.
As a first guess, it takes the line number mentioned in the hunk, plus
or minus any offset used in applying the previous hunk. If that is not
the correct place, <code>patch</code> scans both forward and backward for a
set of lines matching the context given in the hunk.
</p>
<p>First <code>patch</code> looks for a place where all lines of the context
match. If it cannot find such a place, and it is reading a context or
unified diff, and the maximum fuzz factor is set to 1 or more, then
<code>patch</code> makes another scan, ignoring the first and last line of
context. If that fails, and the maximum fuzz factor is set to 2 or
more, it makes another scan, ignoring the first two and last two lines
of context are ignored. It continues similarly if the maximum fuzz
factor is larger.
</p>
<p>The <samp>--fuzz=<var>lines</var></samp> (<samp>-F <var>lines</var></samp>) option sets the
maximum fuzz factor to <var>lines</var>. This option only applies to context
and unified diffs; it ignores up to <var>lines</var> lines while looking for
the place to install a hunk. Note that a larger fuzz factor increases
the odds of making a faulty patch. The default fuzz factor is 2; there
is no point to setting it to more than the number of lines of context
in the diff, ordinarily 3.
</p>
<p>If <code>patch</code> cannot find a place to install a hunk of the patch, it
writes the hunk out to a reject file (see <a href="#Reject-Names">Reject Names</a>, for information
on how reject files are named). It writes out rejected hunks in context
format no matter what form the input patch is in. If the input is a
normal or <code>ed</code> diff, many of the contexts are simply null. The
line numbers on the hunks in the reject file may be different from those
in the patch file: they show the approximate location where <code>patch</code>
thinks the failed hunks belong in the new file rather than in the old
one.
</p>
<p>If the <samp>--verbose</samp> option is given, then
as it completes each hunk <code>patch</code> tells you whether the hunk
succeeded or failed, and if it failed, on which line (in the new file)
<code>patch</code> thinks the hunk should go. If this is different from the
line number specified in the diff, it tells you the offset. A single
large offset <em>may</em> indicate that <code>patch</code> installed a hunk in
the wrong place. <code>patch</code> also tells you if it used a fuzz factor
to make the match, in which case you should also be slightly suspicious.
</p>
<p><code>patch</code> cannot tell if the line numbers are off in an <code>ed</code>
script, and can only detect wrong line numbers in a normal diff when it
finds a change or delete command. It may have the same problem with a
context diff using a fuzz factor equal to or greater than the number of
lines of context shown in the diff (typically 3). In these cases, you
should probably look at a context diff between your original and patched
input files to see if the changes make sense. Compiling without errors
is a pretty good indication that the patch worked, but not a guarantee.
</p>
<p>A patch against an empty file applies to a nonexistent file, and vice
versa. See <a href="#Creating-and-Removing">Creating and Removing</a>.
</p>
<p><code>patch</code> usually produces the correct results, even when it must
make many guesses. However, the results are guaranteed only when
the patch is applied to an exact copy of the file that the patch was
generated from.
</p>
<hr>
<a name="Dry-Runs"></a>
<div class="header">
<p>
Previous: <a href="#Inexact" accesskey="p" rel="prev">Inexact</a>, Up: <a href="#Imperfect" accesskey="u" rel="up">Imperfect</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Predicting-what-patch-will-do"></a>
<h4 class="subsection">10.3.4 Predicting what <code>patch</code> will do</h4>
<a name="index-testing-patch"></a>
<a name="index-dry-runs-for-patch"></a>
<p>It may not be obvious in advance what <code>patch</code> will do with a
complicated or poorly formatted patch. If you are concerned that the
input might cause <code>patch</code> to modify the wrong files, you can
use the <samp>--dry-run</samp> option, which causes <code>patch</code> to
print the results of applying patches without actually changing any
files. You can then inspect the diagnostics generated by the dry run
to see whether <code>patch</code> will modify the files that you expect.
If the patch does not do what you want, you can modify the patch (or
the other options to <code>patch</code>) and try another dry run. Once
you are satisfied with the proposed patch you can apply it by invoking
<code>patch</code> as before, but this time without the
<samp>--dry-run</samp> option.
</p>
<hr>
<a name="Creating-and-Removing"></a>
<div class="header">
<p>
Next: <a href="#Patching-Time-Stamps" accesskey="n" rel="next">Patching Time Stamps</a>, Previous: <a href="#Imperfect" accesskey="p" rel="prev">Imperfect</a>, Up: <a href="#Merging-with-patch" accesskey="u" rel="up">Merging with patch</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Creating-and-Removing-Files"></a>
<h3 class="section">10.4 Creating and Removing Files</h3>
<a name="index-creating-files"></a>
<a name="index-empty-files_002c-removing"></a>
<a name="index-removing-empty-files"></a>
<p>Sometimes when comparing two directories, a file may exist in one
directory but not the other. If you give <code>diff</code> the
<samp>--new-file</samp> (<samp>-N</samp>) option, or if you supply an old or
new file that is named <samp>/dev/null</samp> or is empty and is dated the
Epoch (1970-01-01 00:00:00 UTC), <code>diff</code> outputs a patch that
adds or deletes the contents of this file. When given such a patch,
<code>patch</code> normally creates a new file or removes the old file.
However, when conforming to <acronym>POSIX</acronym> (see <a href="#patch-and-POSIX">patch and POSIX</a>),
<code>patch</code> does not remove the old file, but leaves it empty.
The <samp>--remove-empty-files</samp> (<samp>-E</samp>) option causes
<code>patch</code> to remove output files that are empty after applying a
patch, even if the patch does not appear to be one that removed the
file.
</p>
<p>If the patch appears to create a file that already exists,
<code>patch</code> asks for confirmation before applying the patch.
</p>
<hr>
<a name="Patching-Time-Stamps"></a>
<div class="header">
<p>
Next: <a href="#Multiple-Patches" accesskey="n" rel="next">Multiple Patches</a>, Previous: <a href="#Creating-and-Removing" accesskey="p" rel="prev">Creating and Removing</a>, Up: <a href="#Merging-with-patch" accesskey="u" rel="up">Merging with patch</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Updating-Time-Stamps-on-Patched-Files"></a>
<h3 class="section">10.5 Updating Time Stamps on Patched Files</h3>
<a name="index-time-stamps-on-patched-files"></a>
<p>When <code>patch</code> updates a file, it normally sets the file’s
last-modified time stamp to the current time of day. If you are using
<code>patch</code> to track a software distribution, this can cause
<code>make</code> to incorrectly conclude that a patched file is out of
date. For example, if <samp>syntax.c</samp> depends on <samp>syntax.y</samp>, and
<code>patch</code> updates <samp>syntax.c</samp> and then <samp>syntax.y</samp>, then
<samp>syntax.c</samp> will normally appear to be out of date with respect to
<samp>syntax.y</samp> even though its contents are actually up to date.
</p>
<p>The <samp>--set-utc</samp> (<samp>-Z</samp>) option causes <code>patch</code> to
set a patched file’s modification and access times to the time stamps
given in context diff headers. If the context diff headers do not
specify a time zone, they are assumed to use Coordinated Universal
Time (<acronym>UTC</acronym>, often known as <acronym>GMT</acronym>).
</p>
<p>The <samp>--set-time</samp> (<samp>-T</samp>) option acts like <samp>-Z</samp> or
<samp>--set-utc</samp>, except that it assumes that the context diff
headers’ time stamps use local time instead of <acronym>UTC</acronym>. This option
is not recommended, because patches using local time cannot easily be
used by people in other time zones, and because local time stamps are
ambiguous when local clocks move backwards during daylight-saving time
adjustments. If the context diff headers specify a time zone, this
option is equivalent to <samp>--set-utc</samp> (<samp>-Z</samp>).
</p>
<p><code>patch</code> normally refrains from setting a file’s time stamps if
the file’s original last-modified time stamp does not match the time
given in the diff header, of if the file’s contents do not exactly
match the patch. However, if the <samp>--force</samp> (<samp>-f</samp>)
option is given, the file’s time stamps are set regardless.
</p>
<p>Due to the limitations of the current <code>diff</code> format,
<code>patch</code> cannot update the times of files whose contents have
not changed. Also, if you set file time stamps to values other than
the current time of day, you should also remove (e.g., with ‘<samp>make
clean</samp>’) all files that depend on the patched files, so that later
invocations of <code>make</code> do not get confused by the patched
files’ times.
</p>
<hr>
<a name="Multiple-Patches"></a>
<div class="header">
<p>
Next: <a href="#patch-Directories" accesskey="n" rel="next">patch Directories</a>, Previous: <a href="#Patching-Time-Stamps" accesskey="p" rel="prev">Patching Time Stamps</a>, Up: <a href="#Merging-with-patch" accesskey="u" rel="up">Merging with patch</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Multiple-Patches-in-a-File"></a>
<h3 class="section">10.6 Multiple Patches in a File</h3>
<a name="index-multiple-patches"></a>
<a name="index-intuiting-file-names-from-patches"></a>
<p>If the patch file contains more than one patch, and if you do not
specify an input file on the command line, <code>patch</code> tries to
apply each patch as if they came from separate patch files. This
means that it determines the name of the file to patch for each patch,
and that it examines the leading text before each patch for file names
and prerequisite revision level (see <a href="Making-Patches.html#Making-Patches">Making Patches</a>, for more on
that topic).
</p>
<p><code>patch</code> uses the following rules to intuit a file name from
the leading text before a patch. First, <code>patch</code> takes an
ordered list of candidate file names as follows:
</p>
<ul>
<li> If the header is that of a context diff, <code>patch</code> takes the old
and new file names in the header. A name is ignored if it does not
have enough slashes to satisfy the <samp>-p<var>num</var></samp> or
<samp>--strip=<var>num</var></samp> option. The name <samp>/dev/null</samp> is also
ignored.
</li><li> If there is an ‘<samp>Index:</samp>’ line in the leading garbage and if either
the old and new names are both absent or if <code>patch</code> is
conforming to <acronym>POSIX</acronym>, <code>patch</code> takes the name in the
‘<samp>Index:</samp>’ line.
</li><li> For the purpose of the following rules, the candidate file names are
considered to be in the order (old, new, index), regardless of the
order that they appear in the header.
</li></ul>
<p>Then <code>patch</code> selects a file name from the candidate list as
follows:
</p>
<ul>
<li> If some of the named files exist, <code>patch</code> selects the first
name if conforming to <acronym>POSIX</acronym>, and the best name otherwise.
</li><li> If <code>patch</code> is not ignoring <acronym>RCS</acronym>, ClearCase, and <acronym>SCCS</acronym>
(see <a href="#Revision-Control">Revision Control</a>), and no named files exist but an <acronym>RCS</acronym>,
ClearCase, or <acronym>SCCS</acronym> master is found, <code>patch</code> selects the
first named file with an <acronym>RCS</acronym>, ClearCase, or <acronym>SCCS</acronym> master.
</li><li> If no named files exist, no <acronym>RCS</acronym>, ClearCase, or <acronym>SCCS</acronym> master
was found, some names are given, <code>patch</code> is not conforming to
<acronym>POSIX</acronym>, and the patch appears to create a file, <code>patch</code>
selects the best name requiring the creation of the fewest
directories.
</li><li> If no file name results from the above heuristics, you are asked for
the name of the file to patch, and <code>patch</code> selects that name.
</li></ul>
<p>To determine the <em>best</em> of a nonempty list of file names,
<code>patch</code> first takes all the names with the fewest path name
components; of those, it then takes all the names with the shortest
basename; of those, it then takes all the shortest names; finally, it
takes the first remaining name.
</p>
<p>See <a href="#patch-and-POSIX">patch and POSIX</a>, to see whether <code>patch</code> is conforming
to <acronym>POSIX</acronym>.
</p>
<hr>
<a name="patch-Directories"></a>
<div class="header">
<p>
Next: <a href="#Backups" accesskey="n" rel="next">Backups</a>, Previous: <a href="#Multiple-Patches" accesskey="p" rel="prev">Multiple Patches</a>, Up: <a href="#Merging-with-patch" accesskey="u" rel="up">Merging with patch</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Applying-Patches-in-Other-Directories"></a>
<h3 class="section">10.7 Applying Patches in Other Directories</h3>
<a name="index-directories-and-patch"></a>
<a name="index-patching-directories"></a>
<p>The <samp>--directory=<var>directory</var></samp> (<samp>-d <var>directory</var></samp>)
option to <code>patch</code> makes directory <var>directory</var> the current
directory for interpreting both file names in the patch file, and file
names given as arguments to other options (such as <samp>-B</samp> and
<samp>-o</samp>). For example, while in a mail reading program, you can patch
a file in the <samp>/usr/src/emacs</samp> directory directly from a message
containing the patch like this:
</p>
<div class="example">
<pre class="example">| patch -d /usr/src/emacs
</pre></div>
<p>Sometimes the file names given in a patch contain leading directories,
but you keep your files in a directory different from the one given in
the patch. In those cases, you can use the
<samp>--strip=<var>number</var></samp> (<samp>-p<var>number</var></samp>)
option to set the file name strip count to <var>number</var>. The strip
count tells <code>patch</code> how many slashes, along with the directory
names between them, to strip from the front of file names. A sequence
of one or more adjacent slashes is counted as a single slash. By
default, <code>patch</code> strips off all leading directories, leaving
just the base file names.
</p>
<p>For example, suppose the file name in the patch file is
<samp>/gnu/src/emacs/etc/NEWS</samp>. Using <samp>-p0</samp> gives the
entire file name unmodified, <samp>-p1</samp> gives
<samp>gnu/src/emacs/etc/NEWS</samp> (no leading slash), <samp>-p4</samp> gives
<samp>etc/NEWS</samp>, and not specifying <samp>-p</samp> at all gives <samp>NEWS</samp>.
</p>
<p><code>patch</code> looks for each file (after any slashes have been stripped)
in the current directory, or if you used the <samp>-d <var>directory</var></samp>
option, in that directory.
</p>
<hr>
<a name="Backups"></a>
<div class="header">
<p>
Next: <a href="#Backup-Names" accesskey="n" rel="next">Backup Names</a>, Previous: <a href="#patch-Directories" accesskey="p" rel="prev">patch Directories</a>, Up: <a href="#Merging-with-patch" accesskey="u" rel="up">Merging with patch</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Backup-Files"></a>
<h3 class="section">10.8 Backup Files</h3>
<a name="index-backup-file-strategy"></a>
<p>Normally, <code>patch</code> creates a backup file if the patch does not
exactly match the original input file, because in that case the
original data might not be recovered if you undo the patch with
‘<samp>patch -R</samp>’ (see <a href="#Reversed-Patches">Reversed Patches</a>). However, when conforming
to <acronym>POSIX</acronym>, <code>patch</code> does not create backup files by
default. See <a href="#patch-and-POSIX">patch and POSIX</a>.
</p>
<p>The <samp>--backup</samp> (<samp>-b</samp>) option causes <code>patch</code> to
make a backup file regardless of whether the patch matches the
original input. The <samp>--backup-if-mismatch</samp> option causes
<code>patch</code> to create backup files for mismatches files; this is
the default when not conforming to <acronym>POSIX</acronym>. The
<samp>--no-backup-if-mismatch</samp> option causes <code>patch</code> to not
create backup files, even for mismatched patches; this is the default
when conforming to <acronym>POSIX</acronym>.
</p>
<p>When backing up a file that does not exist, an empty, unreadable
backup file is created as a placeholder to represent the nonexistent
file.
</p>
<hr>
<a name="Backup-Names"></a>
<div class="header">
<p>
Next: <a href="#Reject-Names" accesskey="n" rel="next">Reject Names</a>, Previous: <a href="#Backups" accesskey="p" rel="prev">Backups</a>, Up: <a href="#Merging-with-patch" accesskey="u" rel="up">Merging with patch</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Backup-File-Names"></a>
<h3 class="section">10.9 Backup File Names</h3>
<a name="index-backup-file-names"></a>
<p>Normally, <code>patch</code> renames an original input file into a backup
file by appending to its name the extension ‘<samp>.orig</samp>’, or ‘<samp>~</samp>’
if using ‘<samp>.orig</samp>’ would make the backup file name too
long.<a name="DOCF1" href="#FOOT1"><sup>1</sup></a> The <samp>-z <var>backup-suffix</var></samp> or
<samp>--suffix=<var>backup-suffix</var></samp> option causes <code>patch</code> to
use <var>backup-suffix</var> as the backup extension instead.
</p>
<a name="index-SIMPLE_005fBACKUP_005fSUFFIX"></a>
<p>Alternately, you can specify the extension for backup files with the
<code>SIMPLE_BACKUP_SUFFIX</code> environment variable, which the options
override.
</p>
<p><code>patch</code> can also create numbered backup files the way
<acronym>GNU</acronym> Emacs does. With this method, instead of having a
single backup of each file, <code>patch</code> makes a new backup file
name each time it patches a file. For example, the backups of a file
named <samp>sink</samp> would be called, successively, <samp>sink.~1~</samp>,
<samp>sink.~2~</samp>, <samp>sink.~3~</samp>, etc.
</p>
<a name="index-PATCH_005fVERSION_005fCONTROL"></a>
<a name="index-VERSION_005fCONTROL-1"></a>
<p>The <samp>-V <var>backup-style</var></samp> or
<samp>--version-control=<var>backup-style</var></samp> option takes as an
argument a method for creating backup file names. You can alternately
control the type of backups that <code>patch</code> makes with the
<code>PATCH_VERSION_CONTROL</code> environment variable, which the
<samp>-V</samp> option overrides. If <code>PATCH_VERSION_CONTROL</code> is not
set, the <code>VERSION_CONTROL</code> environment variable is used instead.
Please note that these options and variables control backup file
names; they do not affect the choice of revision control system
(see <a href="#Revision-Control">Revision Control</a>).
</p>
<p>The values of these environment variables and the argument to the
<samp>-V</samp> option are like the <acronym>GNU</acronym> Emacs <code>version-control</code>
variable (see <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Backup-Names.html#Backup-Names">Backup Names</a> in <cite>The <acronym>GNU</acronym> Emacs Manual</cite>,
for more information on backup versions in Emacs). They also
recognize synonyms that are more descriptive. The valid values are
listed below; unique abbreviations are acceptable.
</p>
<dl compact="compact">
<dt><samp>t</samp></dt>
<dt><samp>numbered</samp></dt>
<dd><p>Always make numbered backups.
</p>
</dd>
<dt><samp>nil</samp></dt>
<dt><samp>existing</samp></dt>
<dd><p>Make numbered backups of files that already have them, simple backups of
the others. This is the default.
</p>
</dd>
<dt><samp>never</samp></dt>
<dt><samp>simple</samp></dt>
<dd><p>Always make simple backups.
</p></dd>
</dl>
<p>You can also tell <code>patch</code> to prepend a prefix, such as a
directory name, to produce backup file names. The
<samp>--prefix=<var>prefix</var></samp> (<samp>-B <var>prefix</var></samp>) option makes backup
files by prepending <var>prefix</var> to them. The
<samp>--basename-prefix=<var>prefix</var></samp> (<samp>-Y <var>prefix</var></samp>) prepends
<var>prefix</var> to the last file name component of backup file names
instead; for example, <samp>-Y ~</samp> causes the backup name for
<samp>dir/file.c</samp> to be <samp>dir/~file.c</samp>. If you use either of
these prefix options, the suffix-based options are ignored.
</p>
<p>If you specify the output file with the <samp>-o</samp> option, that file is
the one that is backed up, not the input file.
</p>
<p>Options that affect the names of backup files do not affect whether
backups are made. For example, if you specify the
<samp>--no-backup-if-mismatch</samp> option, none of the options described
in this section have any affect, because no backups are made.
</p>
<hr>
<a name="Reject-Names"></a>
<div class="header">
<p>
Next: <a href="#patch-Messages" accesskey="n" rel="next">patch Messages</a>, Previous: <a href="#Backup-Names" accesskey="p" rel="prev">Backup Names</a>, Up: <a href="#Merging-with-patch" accesskey="u" rel="up">Merging with patch</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Reject-File-Names"></a>
<h3 class="section">10.10 Reject File Names</h3>
<a name="index-reject-file-names"></a>
<p>The names for reject files (files containing patches that
<code>patch</code> could not find a place to apply) are normally the name
of the output file with ‘<samp>.rej</samp>’ appended (or ‘<samp>#</samp>’ if using
‘<samp>.rej</samp>’ would make the backup file name too long).
</p>
<p>Alternatively, you can tell <code>patch</code> to place all of the rejected
patches in a single file. The <samp>-r <var>reject-file</var></samp> or
<samp>--reject-file=<var>reject-file</var></samp> option uses <var>reject-file</var> as
the reject file name.
</p>
<hr>
<a name="patch-Messages"></a>
<div class="header">
<p>
Next: <a href="#patch-and-POSIX" accesskey="n" rel="next">patch and POSIX</a>, Previous: <a href="#Reject-Names" accesskey="p" rel="prev">Reject Names</a>, Up: <a href="#Merging-with-patch" accesskey="u" rel="up">Merging with patch</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Messages-and-Questions-from-patch"></a>
<h3 class="section">10.11 Messages and Questions from <code>patch</code></h3>
<a name="index-patch-messages-and-questions"></a>
<a name="index-diagnostics-from-patch"></a>
<a name="index-messages-from-patch"></a>
<p><code>patch</code> can produce a variety of messages, especially if it
has trouble decoding its input. In a few situations where it’s not
sure how to proceed, <code>patch</code> normally prompts you for more
information from the keyboard. There are options to produce more or
fewer messages, to have it not ask for keyboard input, and to
affect the way that file names are quoted in messages.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#More-or-Fewer-Messages" accesskey="1">More or Fewer Messages</a>:</td><td> </td><td align="left" valign="top">Controlling the verbosity of <code>patch</code>.
</td></tr>
<tr><td align="left" valign="top">• <a href="#patch-and-Keyboard-Input" accesskey="2">patch and Keyboard Input</a>:</td><td> </td><td align="left" valign="top">Inhibiting keyboard input.
</td></tr>
<tr><td align="left" valign="top">• <a href="#patch-Quoting-Style" accesskey="3">patch Quoting Style</a>:</td><td> </td><td align="left" valign="top">Quoting file names in diagnostics.
</td></tr>
</table>
<p><code>patch</code> exits with status 0 if all hunks are applied successfully,
1 if some hunks cannot be applied, and 2 if there is more serious trouble.
When applying a set of patches in a loop, you should check the
exit status, so you don’t apply a later patch to a partially patched
file.
</p>
<hr>
<a name="More-or-Fewer-Messages"></a>
<div class="header">
<p>
Next: <a href="#patch-and-Keyboard-Input" accesskey="n" rel="next">patch and Keyboard Input</a>, Up: <a href="#patch-Messages" accesskey="u" rel="up">patch Messages</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Controlling-the-Verbosity-of-patch"></a>
<h4 class="subsection">10.11.1 Controlling the Verbosity of <code>patch</code></h4>
<a name="index-verbose-messages-from-patch"></a>
<a name="index-inhibit-messages-from-patch"></a>
<p>You can cause <code>patch</code> to produce more messages by using the
<samp>--verbose</samp> option. For example, when you give this option,
the message ‘<samp>Hmm...</samp>’ indicates that <code>patch</code> is reading text in
the patch file, attempting to determine whether there is a patch in that
text, and if so, what kind of patch it is.
</p>
<p>You can inhibit all terminal output from <code>patch</code>, unless an error
occurs, by using the <samp>-s</samp>, <samp>--quiet</samp>, or <samp>--silent</samp>
option.
</p>
<hr>
<a name="patch-and-Keyboard-Input"></a>
<div class="header">
<p>
Next: <a href="#patch-Quoting-Style" accesskey="n" rel="next">patch Quoting Style</a>, Previous: <a href="#More-or-Fewer-Messages" accesskey="p" rel="prev">More or Fewer Messages</a>, Up: <a href="#patch-Messages" accesskey="u" rel="up">patch Messages</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Inhibiting-Keyboard-Input"></a>
<h4 class="subsection">10.11.2 Inhibiting Keyboard Input</h4>
<a name="index-keyboard-input-to-patch"></a>
<p>There are two ways you can prevent <code>patch</code> from asking you any
questions. The <samp>--force</samp> (<samp>-f</samp>) option assumes that you know
what you are doing. It causes <code>patch</code> to do the following:
</p>
<ul>
<li> Skip patches that do not contain file names in their headers.
</li><li> Patch files even though they have the wrong version for the
‘<samp>Prereq:</samp>’ line in the patch;
</li><li> Assume that patches are not reversed even if they look like they are.
</li></ul>
<p>The <samp>--batch</samp> (<samp>-t</samp>) option is similar to <samp>-f</samp>, in that
it suppresses questions, but it makes somewhat different assumptions:
</p>
<ul>
<li> Skip patches that do not contain file names in their headers
(the same as <samp>-f</samp>).
</li><li> Skip patches for which the file has the wrong version for the
‘<samp>Prereq:</samp>’ line in the patch;
</li><li> Assume that patches are reversed if they look like they are.
</li></ul>
<hr>
<a name="patch-Quoting-Style"></a>
<div class="header">
<p>
Previous: <a href="#patch-and-Keyboard-Input" accesskey="p" rel="prev">patch and Keyboard Input</a>, Up: <a href="#patch-Messages" accesskey="u" rel="up">patch Messages</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="patch-Quoting-Style-1"></a>
<h4 class="subsection">10.11.3 <code>patch</code> Quoting Style</h4>
<a name="index-quoting-style"></a>
<p>When <code>patch</code> outputs a file name in a diagnostic message, it
can format the name in any of several ways. This can be useful to
output file names unambiguously, even if they contain punctuation or
special characters like newlines. The
<samp>--quoting-style=<var>word</var></samp> option controls how names are
output. The <var>word</var> should be one of the following:
</p>
<dl compact="compact">
<dt>‘<samp>literal</samp>’</dt>
<dd><p>Output names as-is.
</p></dd>
<dt>‘<samp>shell</samp>’</dt>
<dd><p>Quote names for the shell if they contain shell metacharacters or would
cause ambiguous output.
</p></dd>
<dt>‘<samp>shell-always</samp>’</dt>
<dd><p>Quote names for the shell, even if they would normally not require quoting.
</p></dd>
<dt>‘<samp>c</samp>’</dt>
<dd><p>Quote names as for a C language string.
</p></dd>
<dt>‘<samp>escape</samp>’</dt>
<dd><p>Quote as with ‘<samp>c</samp>’ except omit the surrounding double-quote
characters.
</p></dd>
</dl>
<a name="index-QUOTING_005fSTYLE"></a>
<p>You can specify the default value of the <samp>--quoting-style</samp>
option with the environment variable <code>QUOTING_STYLE</code>. If that
environment variable is not set, the default value is ‘<samp>shell</samp>’,
but this default may change in a future version of <code>patch</code>.
</p>
<hr>
<a name="patch-and-POSIX"></a>
<div class="header">
<p>
Next: <a href="#patch-and-Tradition" accesskey="n" rel="next">patch and Tradition</a>, Previous: <a href="#patch-Messages" accesskey="p" rel="prev">patch Messages</a>, Up: <a href="#Merging-with-patch" accesskey="u" rel="up">Merging with patch</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="patch-and-the-POSIX-Standard"></a>
<h3 class="section">10.12 <code>patch</code> and the <acronym>POSIX</acronym> Standard</h3>
<a name="index-POSIX"></a>
<a name="index-POSIXLY_005fCORRECT"></a>
<p>If you specify the <samp>--posix</samp> option, or set the
<code>POSIXLY_CORRECT</code> environment variable, <code>patch</code> conforms
more strictly to the <acronym>POSIX</acronym> standard, as follows:
</p>
<ul>
<li> Take the first existing file from the list (old, new, index)
when intuiting file names from diff headers. See <a href="#Multiple-Patches">Multiple Patches</a>.
</li><li> Do not remove files that are removed by a diff.
See <a href="#Creating-and-Removing">Creating and Removing</a>.
</li><li> Do not ask whether to get files from <acronym>RCS</acronym>, ClearCase, or
<acronym>SCCS</acronym>. See <a href="#Revision-Control">Revision Control</a>.
</li><li> Require that all options precede the files in the command line.
</li><li> Do not backup files, even when there is a mismatch. See <a href="#Backups">Backups</a>.
</li></ul>
<hr>
<a name="patch-and-Tradition"></a>
<div class="header">
<p>
Previous: <a href="#patch-and-POSIX" accesskey="p" rel="prev">patch and POSIX</a>, Up: <a href="#Merging-with-patch" accesskey="u" rel="up">Merging with patch</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="GNU-patch-and-Traditional-patch"></a>
<h3 class="section">10.13 <acronym>GNU</acronym> <code>patch</code> and Traditional <code>patch</code></h3>
<a name="index-traditional-patch"></a>
<p>The current version of <acronym>GNU</acronym> <code>patch</code> normally follows the
<acronym>POSIX</acronym> standard. See <a href="#patch-and-POSIX">patch and POSIX</a>, for the few exceptions
to this general rule.
</p>
<p>Unfortunately, <acronym>POSIX</acronym> redefined the behavior of <code>patch</code> in
several important ways. You should be aware of the following
differences if you must interoperate with traditional <code>patch</code>,
or with <acronym>GNU</acronym> <code>patch</code> version 2.1 and earlier.
</p>
<ul>
<li> In traditional <code>patch</code>, the <samp>-p</samp> option’s operand was
optional, and a bare <samp>-p</samp> was equivalent to <samp>-p0</samp>. The
<samp>-p</samp> option now requires an operand, and <samp>-p 0</samp> is now
equivalent to <samp>-p0</samp>. For maximum compatibility, use options
like <samp>-p0</samp> and <samp>-p1</samp>.
<p>Also, traditional <code>patch</code> simply counted slashes when
stripping path prefixes; <code>patch</code> now counts pathname
components. That is, a sequence of one or more adjacent slashes now
counts as a single slash. For maximum portability, avoid sending
patches containing <samp>//</samp> in file names.
</p>
</li><li> In traditional <code>patch</code>, backups were enabled by default. This
behavior is now enabled with the <samp>--backup</samp> (<samp>-b</samp>)
option.
<p>Conversely, in <acronym>POSIX</acronym> <code>patch</code>, backups are never made,
even when there is a mismatch. In <acronym>GNU</acronym> <code>patch</code>, this
behavior is enabled with the <samp>--no-backup-if-mismatch</samp> option,
or by conforming to <acronym>POSIX</acronym>.
</p>
<p>The <samp>-b <var>suffix</var></samp> option of traditional <code>patch</code> is
equivalent to the ‘<samp>-b -z <var>suffix</var></samp>’ options of <acronym>GNU</acronym>
<code>patch</code>.
</p>
</li><li> Traditional <code>patch</code> used a complicated (and incompletely
documented) method to intuit the name of the file to be patched from
the patch header. This method did not conform to <acronym>POSIX</acronym>, and had
a few gotchas. Now <code>patch</code> uses a different, equally
complicated (but better documented) method that is optionally
<acronym>POSIX</acronym>-conforming; we hope it has fewer gotchas. The two methods
are compatible if the file names in the context diff header and the
‘<samp>Index:</samp>’ line are all identical after prefix-stripping. Your
patch is normally compatible if each header’s file names all contain
the same number of slashes.
</li><li> When traditional <code>patch</code> asked the user a question, it sent
the question to standard error and looked for an answer from the first
file in the following list that was a terminal: standard error,
standard output, <samp>/dev/tty</samp>, and standard input. Now
<code>patch</code> sends questions to standard output and gets answers
from <samp>/dev/tty</samp>. Defaults for some answers have been changed so
that <code>patch</code> never goes into an infinite loop when using
default answers.
</li><li> Traditional <code>patch</code> exited with a status value that counted
the number of bad hunks, or with status 1 if there was real trouble.
Now <code>patch</code> exits with status 1 if some hunks failed, or with
2 if there was real trouble.
</li><li> Limit yourself to the following options when sending instructions
meant to be executed by anyone running <acronym>GNU</acronym> <code>patch</code>,
traditional <code>patch</code>, or a <code>patch</code> that conforms to
<acronym>POSIX</acronym>. Spaces are significant in the following list, and
operands are required.
<div class="example">
<pre class="example"><samp>-c</samp>
<samp>-d <var>dir</var></samp>
<samp>-D <var>define</var></samp>
<samp>-e</samp>
<samp>-l</samp>
<samp>-n</samp>
<samp>-N</samp>
<samp>-o <var>outfile</var></samp>
<samp>-p<var>num</var></samp>
<samp>-R</samp>
<samp>-r <var>rejectfile</var></samp>
</pre></div>
</li></ul>
<div class="footnote">
<hr>
<h4 class="footnotes-heading">Footnotes</h4>
<h3><a name="FOOT1" href="#DOCF1">(1)</a></h3>
<p>A coding error in <acronym>GNU</acronym> <code>patch</code> version
2.5.4 causes it to always use ‘<samp>~</samp>’, but this should be fixed in
the next release.</p>
</div>
<hr>
<div class="header">
<p>
Previous: <a href="#patch-and-POSIX" accesskey="p" rel="prev">patch and POSIX</a>, Up: <a href="#Merging-with-patch" accesskey="u" rel="up">Merging with patch</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|