/usr/share/doc/diffutils-doc/diffutils_11.html is in diffutils-doc 1:3.2-1ubuntu1.
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 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
<html>
<!-- This manual is for GNU Diffutils
(version 3.2, 15 August 2011),
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-2011 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 on March 19, 2012 by texi2html 1.82
texi2html was written by:
Lionel Cons <Lionel.Cons@cern.ch> (original author)
Karl Berry <karl@freefriends.org>
Olaf Bachmann <obachman@mathematik.uni-kl.de>
and many others.
Maintained by: Many creative people.
Send bugs and suggestions to <texi2html-bug@nongnu.org>
-->
<head>
<title>Comparing and Merging Files: 10. Merging with patch</title>
<meta name="description" content="Comparing and Merging Files: 10. Merging with patch">
<meta name="keywords" content="Comparing and Merging Files: 10. Merging with patch">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2html 1.82">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
pre.display {font-family: serif}
pre.format {font-family: serif}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: serif; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: serif; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.roman {font-family:serif; font-weight:normal;}
span.sansserif {font-family:sans-serif; font-weight:normal;}
ul.toc {list-style: none}
-->
</style>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Merging-with-patch"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="diffutils_10.html#Merge-Commands" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#patch-Input" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils_10.html#Interactive-Merging" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Merging-with-patch-1"></a>
<h1 class="chapter">10. Merging with <code>patch</code></h1>
<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 section <a href="diffutils_2.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 section <a href="diffutils_16.html#Invoking-patch">Invoking <code>patch</code></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">10.1 Selecting the <code>patch</code> Input Format</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">10.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">10.3 Applying Imperfect Patches</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">10.4 Creating and Removing Files</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">10.5 Updating Time Stamps on Patched Files</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">10.6 Multiple Patches in a File</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">10.7 Applying Patches in Other 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">10.8 Backup Files</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">10.9 Backup File 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">10.10 Reject File 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">10.11 Messages and Questions from <code>patch</code></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">10.12 <code>patch</code> and the <acronym>POSIX</acronym> Standard</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">10.13 <acronym>GNU</acronym> <code>patch</code> and Traditional <code>patch</code></a></td><td> </td><td align="left" valign="top"> <acronym>GNU</acronym> versus traditional <code>patch</code>.
</td></tr>
</table>
<hr size="6">
<a name="patch-Input"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Merging-with-patch" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Revision-Control" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Selecting-the-patch-Input-Format"></a>
<h2 class="section">10.1 Selecting the <code>patch</code> Input Format</h2>
<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 size="6">
<a name="Revision-Control"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#patch-Input" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Imperfect" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Revision-Control-1"></a>
<h2 class="section">10.2 Revision Control</h2>
<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 section <a href="#patch-and-POSIX"><code>patch</code> and the <acronym>POSIX</acronym> Standard</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 section <a href="#Backup-Names">Backup File Names</a>).
</p>
<hr size="6">
<a name="Imperfect"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Revision-Control" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Changed-White-Space" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Applying-Imperfect-Patches"></a>
<h2 class="section">10.3 Applying Imperfect Patches</h2>
<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>- </samp>’ 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">10.3.1 Applying Patches with 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">10.3.2 Applying 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">10.3.3 Helping <code>patch</code> Find Inexact Matches</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">10.3.4 Predicting what <code>patch</code> will do</a></td><td> </td><td align="left" valign="top"></td></tr>
</table>
<hr size="6">
<a name="Changed-White-Space"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Imperfect" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Reversed-Patches" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Imperfect" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Applying-Patches-with-Changed-White-Space"></a>
<h3 class="subsection">10.3.1 Applying Patches with Changed White Space</h3>
<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 size="6">
<a name="Reversed-Patches"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Changed-White-Space" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Inexact" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Imperfect" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Applying-Reversed-Patches"></a>
<h3 class="subsection">10.3.2 Applying Reversed Patches</h3>
<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 size="6">
<a name="Inexact"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Reversed-Patches" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Dry-Runs" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Imperfect" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Helping-patch-Find-Inexact-Matches"></a>
<h3 class="subsection">10.3.3 Helping <code>patch</code> Find Inexact Matches</h3>
<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 section <a href="#Reject-Names">Reject File 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 section <a href="#Creating-and-Removing">Creating and Removing Files</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 size="6">
<a name="Dry-Runs"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Inexact" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Creating-and-Removing" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Imperfect" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Predicting-what-patch-will-do"></a>
<h3 class="subsection">10.3.4 Predicting what <code>patch</code> will do</h3>
<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 size="6">
<a name="Creating-and-Removing"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Dry-Runs" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Patching-Time-Stamps" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Creating-and-Removing-Files"></a>
<h2 class="section">10.4 Creating and Removing Files</h2>
<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 ‘<tt>/dev/null</tt>’ 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 section <a href="#patch-and-POSIX"><code>patch</code> and the <acronym>POSIX</acronym> Standard</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 size="6">
<a name="Patching-Time-Stamps"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Creating-and-Removing" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Multiple-Patches" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Updating-Time-Stamps-on-Patched-Files"></a>
<h2 class="section">10.5 Updating Time Stamps on Patched Files</h2>
<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 ‘<tt>syntax.c</tt>’ depends on ‘<tt>syntax.y</tt>’, and
<code>patch</code> updates ‘<tt>syntax.c</tt>’ and then ‘<tt>syntax.y</tt>’, then
‘<tt>syntax.c</tt>’ will normally appear to be out of date with respect to
‘<tt>syntax.y</tt>’ 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 size="6">
<a name="Multiple-Patches"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Patching-Time-Stamps" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#patch-Directories" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Multiple-Patches-in-a-File"></a>
<h2 class="section">10.6 Multiple Patches in a File</h2>
<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 section <a href="diffutils_12.html#Making-Patches">Tips for Making and Using 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 ‘<tt>/dev/null</tt>’ 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 section <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 section <a href="#patch-and-POSIX"><code>patch</code> and the <acronym>POSIX</acronym> Standard</a>, to see whether <code>patch</code> is conforming
to <acronym>POSIX</acronym>.
</p>
<hr size="6">
<a name="patch-Directories"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Multiple-Patches" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Backups" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Applying-Patches-in-Other-Directories"></a>
<h2 class="section">10.7 Applying Patches in Other Directories</h2>
<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 ‘<tt>/usr/src/emacs</tt>’ directory directly from a message
containing the patch like this:
</p>
<table><tr><td> </td><td><pre class="example">| patch -d /usr/src/emacs
</pre></td></tr></table>
<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
‘<tt>/gnu/src/emacs/etc/NEWS</tt>’. Using ‘<samp>-p0</samp>’ gives the
entire file name unmodified, ‘<samp>-p1</samp>’ gives
‘<tt>gnu/src/emacs/etc/NEWS</tt>’ (no leading slash), ‘<samp>-p4</samp>’ gives
‘<tt>etc/NEWS</tt>’, and not specifying ‘<samp>-p</samp>’ at all gives ‘<tt>NEWS</tt>’.
</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 size="6">
<a name="Backups"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#patch-Directories" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Backup-Names" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Backup-Files"></a>
<h2 class="section">10.8 Backup Files</h2>
<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 section <a href="#Reversed-Patches">Applying Reversed Patches</a>). However, when conforming
to <acronym>POSIX</acronym>, <code>patch</code> does not create backup files by
default. See section <a href="#patch-and-POSIX"><code>patch</code> and the <acronym>POSIX</acronym> Standard</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 size="6">
<a name="Backup-Names"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Backups" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Reject-Names" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Backup-File-Names"></a>
<h2 class="section">10.9 Backup File Names</h2>
<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="diffutils_fot.html#FOOT1">(1)</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 ‘<tt>sink</tt>’ would be called, successively, ‘<tt>sink.~1~</tt>’,
‘<tt>sink.~2~</tt>’, ‘<tt>sink.~3~</tt>’, 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 section <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="../emacs/Backup-Names.html#Backup-Names">(emacs)Backup Names</a> section ‘Backup Names’ 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
‘<tt>dir/file.c</tt>’ to be ‘<tt>dir/~file.c</tt>’. 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 size="6">
<a name="Reject-Names"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Backup-Names" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#patch-Messages" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Reject-File-Names"></a>
<h2 class="section">10.10 Reject File Names</h2>
<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 size="6">
<a name="patch-Messages"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Reject-Names" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#More-or-Fewer-Messages" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Messages-and-Questions-from-patch"></a>
<h2 class="section">10.11 Messages and Questions from <code>patch</code></h2>
<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">10.11.1 Controlling the Verbosity of <code>patch</code></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">10.11.2 Inhibiting 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">10.11.3 <code>patch</code> 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 size="6">
<a name="More-or-Fewer-Messages"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#patch-Messages" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#patch-and-Keyboard-Input" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#patch-Messages" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Controlling-the-Verbosity-of-patch"></a>
<h3 class="subsection">10.11.1 Controlling the Verbosity of <code>patch</code></h3>
<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 size="6">
<a name="patch-and-Keyboard-Input"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#More-or-Fewer-Messages" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#patch-Quoting-Style" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#patch-Messages" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Inhibiting-Keyboard-Input"></a>
<h3 class="subsection">10.11.2 Inhibiting Keyboard Input</h3>
<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 size="6">
<a name="patch-Quoting-Style"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#patch-and-Keyboard-Input" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#patch-and-POSIX" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#patch-Messages" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="patch-Quoting-Style-1"></a>
<h3 class="subsection">10.11.3 <code>patch</code> Quoting Style</h3>
<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 size="6">
<a name="patch-and-POSIX"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#patch-Quoting-Style" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#patch-and-Tradition" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="patch-and-the-POSIX-Standard"></a>
<h2 class="section">10.12 <code>patch</code> and the <acronym>POSIX</acronym> Standard</h2>
<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 section <a href="#Multiple-Patches">Multiple Patches in a File</a>.
</li><li>
Do not remove files that are removed by a diff.
See section <a href="#Creating-and-Removing">Creating and Removing Files</a>.
</li><li>
Do not ask whether to get files from <acronym>RCS</acronym>, ClearCase, or
<acronym>SCCS</acronym>. See section <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 section <a href="#Backups">Backup Files</a>.
</li></ul>
<hr size="6">
<a name="patch-and-Tradition"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#patch-and-POSIX" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Merging-with-patch" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="GNU-patch-and-Traditional-patch"></a>
<h2 class="section">10.13 <acronym>GNU</acronym> <code>patch</code> and Traditional <code>patch</code></h2>
<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 section <a href="#patch-and-POSIX"><code>patch</code> and the <acronym>POSIX</acronym> Standard</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 ‘<tt>//</tt>’ 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, ‘<tt>/dev/tty</tt>’, and standard input. Now
<code>patch</code> sends questions to standard output and gets answers
from ‘<tt>/dev/tty</tt>’. 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.
<table><tr><td> </td><td><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></td></tr></table>
</li></ul>
<hr size="6">
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Merging-with-patch" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="diffutils_12.html#Making-Patches" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="diffutils.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_22.html#Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="diffutils_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<p>
<font size="-1">
This document was generated by <em>root</em> on <em>March 19, 2012</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html 1.82</em></a>.
</font>
<br>
</p>
</body>
</html>
|