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
|
.\" patch man page
.ds = \-\^\-
.de Sp
.if t .sp .3
.if n .sp
..
.TH PATCH 1 "" GNU
.SH NAME
patch \- apply a diff file to an original
.SH SYNOPSIS
.B patch
.RI [ options ]
.RI [ originalfile
.RI [ patchfile ]]
.Sp
but usually just
.Sp
.BI "patch \-p" "num"
.BI < patchfile
.SH DESCRIPTION
.B patch
takes a patch file
.I patchfile
containing a difference listing produced by the
.B diff
program and applies those differences to one or more original files,
producing patched versions.
Normally the patched versions are put in place of the originals.
Backups can be made; see the
.B \-b
or
.B \*=backup
option.
The names of the files to be patched are usually taken from the patch file,
but if there's just one file to be patched it can be specified on the
command line as
.IR originalfile .
.PP
Upon startup, patch attempts to determine the type of the diff listing,
unless overruled by a
\fB\-c\fP (\fB\*=context\fP),
\fB\-e\fP (\fB\*=ed\fP),
\fB\-n\fP (\fB\*=normal\fP),
or
\fB\-u\fP (\fB\*=unified\fP)
option.
Context diffs (old-style, new-style, and unified) and
normal diffs are applied by the
.B patch
program itself, while
.B ed
diffs are simply fed to the
.BR ed (1)
editor via a pipe.
.PP
.B patch
tries to skip any leading garbage, apply the diff,
and then skip any trailing garbage.
Thus you could feed an article or message containing a
diff listing to
.BR patch ,
and it should work.
If the entire diff is indented by a consistent amount, if lines end in \s-1CRLF\s0,
or if a diff is encapsulated one or more times by prepending
"\fB\- \fP" to lines starting with "\fB\-\fP" as specified by Internet RFC 934,
this is taken into account.
After removing indenting or encapsulation,
lines beginning with
.B #
are ignored, as they are considered to be comments.
.PP
With context diffs, and to a lesser extent with normal diffs,
.B patch
can detect when the line numbers mentioned in the patch are incorrect,
and attempts to find the correct place to apply each hunk of the patch.
As a first guess, it takes the line number mentioned for the hunk, plus or
minus any offset used in applying the previous hunk.
If that is not the correct place,
.B patch
scans both forwards and backwards for a set of lines matching the context
given in the hunk.
First
.B patch
looks for a place where all lines of the context match.
If no such place is found, and it's a context diff, and the maximum fuzz factor
is set to 1 or more, then another scan takes place ignoring the first and last
line of context.
If that fails, and the maximum fuzz factor is set to 2 or more,
the first two and last two lines of context are ignored,
and another scan is made.
(The default maximum fuzz factor is 2.)
.PP
Hunks with less prefix context than suffix context (after applying fuzz)
must apply at the start of the file if their first line number is\ 1. Hunks
with more prefix context than suffix context (after applying fuzz) must apply
at the end of the file.
.PP
If
.B patch
cannot find a place to install that hunk of the patch, it puts the
hunk out to a reject file, which normally is the name of the output file
plus a
.B \&.rej
suffix, or
.B #
if
.B \&.rej
would generate a file name that is too long
(if even appending the single character
.B #
makes the file name too long, then
.B #
replaces the file name's last character).
.PP
The rejected hunk comes out in unified or context diff format.
If the input was a normal diff, many of the contexts are simply null.
The line numbers on the hunks in the reject file may be different than
in the patch file: they reflect the approximate location patch thinks the
failed hunks belong in the new file rather than the old one.
.PP
As each hunk is completed, you are told if the hunk
failed, and if so which line (in the new file)
.B patch
thought the hunk should go on.
If the hunk is installed at a different line
from the line number specified in the diff, you
are told the offset.
A single large offset
.I may
indicate that a hunk was installed in the
wrong place.
You are also told if a fuzz factor was used to make the match, in which
case you should also be slightly suspicious.
If the
.B \*=verbose
option is given, you are also told about hunks that match exactly.
.PP
If no original file
.I origfile
is specified on the command line,
.B patch
tries to figure out from the leading garbage what the name of the file
to edit is, using the following rules.
.LP
First,
.B patch
takes an ordered list of candidate file names as follows:
.TP 3
.B " \(bu"
If the header is that of a context diff,
.B patch
takes the old and new file names in the header.
A name is ignored if it does not have enough slashes to satisfy the
.BI \-p num
or
.BI \*=strip= num
option.
The name
.B /dev/null
is also ignored.
.TP
.B " \(bu"
If there is an
.B Index:\&
line in the leading garbage
and if either the old and new names are both absent or if
.B patch
is conforming to \s-1POSIX\s0,
.B patch
takes the name in the
.B Index:\&
line.
.TP
.B " \(bu"
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.
.LP
Then
.B patch
selects a file name from the candidate list as follows:
.TP 3
.B " \(bu"
If some of the named files exist,
.B patch
selects the first name if conforming to \s-1POSIX\s0,
and the best name otherwise.
.TP
.B " \(bu"
If
.B patch
is not ignoring \s-1RCS\s0, ClearCase, Perforce, and \s-1SCCS\s0 (see the
.BI "\-g\ " num
or
.BI \*=get= num
option), and no named files exist
but an \s-1RCS\s0, ClearCase, Perforce, or \s-1SCCS\s0 master is found,
.B patch
selects the first named file
with an \s-1RCS\s0, ClearCase, Perforce, or \s-1SCCS\s0 master.
.TP
.B " \(bu"
If no named files exist,
no \s-1RCS\s0, ClearCase, Perforce, or \s-1SCCS\s0 master was found,
some names are given,
.B patch
is not conforming to \s-1POSIX\s0,
and the patch appears to create a file,
.B patch
selects the best name requiring the creation of the fewest directories.
.TP
.B " \(bu"
If no file name results from the above heuristics, you are asked
for the name of the file to patch, and
.B patch
selects that name.
.LP
To determine the
.I best
of a nonempty list of file names,
.B patch
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.
.PP
Additionally, if the leading garbage contains a
.B Prereq:\&
line,
.B patch
takes the first word from the prerequisites line (normally a version
number) and checks the original file to see if that word can be found.
If not,
.B patch
asks for confirmation before proceeding.
.PP
The upshot of all this is that you should be able to say, while in a news
interface, something like the following:
.Sp
.RS
\fB| patch \-d /usr/src/local/blurfl\fP
.RE
.Sp
and patch a file in the
.B blurfl
directory directly from the article containing
the patch.
.PP
If the patch file contains more than one patch,
.B patch
tries to apply each of them as if they came from separate patch files.
This means, among other things, that it is assumed that the name of the file
to patch must be determined for each diff listing,
and that the garbage before each diff listing
contains interesting things such as file names and revision level, as
mentioned previously.
.SH OPTIONS
.TP 3
\fB\-b\fP or \fB\*=backup\fP
Make backup files.
That is, when patching a file,
rename or copy the original instead of removing it.
See the
.B \-V
or
.B \*=version\-control
option for details about how backup file names are determined.
.TP
.B \*=backup\-if\-mismatch
Back up a file if the patch does not match the file exactly
and if backups are not otherwise requested.
This is the default unless
.B patch
is conforming to \s-1POSIX\s0.
.TP
.B \*=no\-backup\-if\-mismatch
Do not back up a file if the patch does not match the file exactly
and if backups are not otherwise requested.
This is the default if
.B patch
is conforming to \s-1POSIX\s0.
.TP
\fB\-B\fP \fIpref\fP or \fB\*=prefix=\fP\fIpref\fP
Use the
.B simple
method to determine backup file names (see the
.BI "\-V " method
or
.BI "\*=version\-control " method
option), and append
.I pref
to a file name when generating its backup file name.
For example, with
.B "\-B\ /junk/"
the simple backup file name for
.B src/patch/util.c
is
.BR /junk/src/patch/util.c .
.TP
\fB\*=binary\fP
Write all files in binary mode, except for standard output and
.BR /dev/tty .
When reading, disable the heuristic for transforming CRLF line endings into LF
line endings. This option is needed on \s-1POSIX\s0 systems when applying patches
generated on non-\s-1POSIX\s0 systems to non-\s-1POSIX\s0 files.
(On \s-1POSIX\s0 systems, file reads and writes never transform line
endings. On Windows, reads and writes do transform line endings by default,
and patches should be generated by
.B "diff\ \*=binary"
when line endings are significant.)
.TP
\fB\-c\fP or \fB\*=context\fP
Interpret the patch file as a ordinary context diff.
.TP
\fB\-d\fP \fIdir\fP or \fB\*=directory=\fP\fIdir\fP
Change to the directory
.I dir
immediately, before doing
anything else.
.TP
\fB\-D\fP \fIdefine\fP or \fB\*=ifdef=\fP\fIdefine\fP
Use the
.BR #ifdef " .\|.\|. " #endif
construct to mark changes, with
.I define
as the differentiating symbol.
.TP
.B "\*=dry\-run"
Print the results of applying the patches without actually changing any files.
.TP
\fB\-e\fP or \fB\*=ed\fP
Interpret the patch file as an
.B ed
script.
.TP
\fB\-E\fP or \fB\*=remove\-empty\-files\fP
Remove output files that are empty after the patches have been applied.
Normally this option is unnecessary, since
.B patch
can examine the time stamps on the header to determine whether a file
should exist after patching.
However, if the input is not a context diff or if
.B patch
is conforming to \s-1POSIX\s0,
.B patch
does not remove empty patched files unless this option is given.
When
.B patch
removes a file, it also attempts to remove any empty ancestor directories.
.TP
\fB\-f\fP or \fB\*=force\fP
Assume that the user knows exactly what he or she is doing, and do not
ask any questions. Skip patches whose headers
do not say which file is to be patched; patch files even though they have the
wrong version for the
.B Prereq:\&
line in the patch; and assume that
patches are not reversed even if they look like they are.
This option does not suppress commentary; use
.B \-s
for that.
.TP
\fB\-F\fP \fInum\fP or \fB\*=fuzz=\fP\fInum\fP
Set the maximum fuzz factor.
This option only applies to diffs that have context, and causes
.B patch
to ignore up to that many lines of context in looking for places to install a hunk.
Note that a larger fuzz factor increases the odds of a faulty patch.
The default fuzz factor is 2. A fuzz factor greater than or equal to the
number of lines of context in the context diff, ordinarily 3, ignores all
context.
.TP
\fB\-g\fP \fInum\fP or \fB\*=get=\fP\fInum\fP
This option controls
.BR patch 's
actions when a file is under \s-1RCS\s0 or \s-1SCCS\s0 control,
and does not exist or is read-only and matches the default version,
or when a file is under ClearCase or Perforce control and does not exist.
If
.I num
is positive,
.B patch
gets (or checks out) the file from the revision control system; if zero,
.B patch
ignores \s-1RCS\s0, ClearCase, Perforce, and \s-1SCCS\s0
and does not get the file; and if negative,
.B patch
asks the user whether to get the file.
The default value of this option is given by the value of the
.B PATCH_GET
environment variable if it is set; if not, the default value is zero.
.TP
.B "\*=help"
Print a summary of options and exit.
.TP
\fB\-i\fP \fIpatchfile\fP or \fB\*=input=\fP\fIpatchfile\fP
Read the patch from
.IR patchfile .
If
.I patchfile
is
.BR \- ,
read from standard input, the default.
.TP
\fB\-l\fP or \fB\*=ignore\-whitespace\fP
Match patterns loosely, in case tabs or spaces
have been munged in your files.
Any sequence of one or more blanks in the patch file matches any sequence
in the original file, and sequences of blanks at the ends of lines are ignored.
Normal characters must still match exactly.
Each line of the context must still match a line in the original file.
.TP
\fB\*=merge\fP or \fB\*=merge=merge\fP or \fB\*=merge=diff3\fP
Merge a patch file into the original files similar to \fBdiff3\fP(1) or
\fBmerge\fP(1). If a conflict is found, \fBpatch\fP outputs a warning and
brackets the conflict with \fB<<<<<<<\fP and \fB>>>>>>>\fP lines.
A typical conflict will look like this:
.LP
.RS
.nf
.B <<<<<<<
.I lines from the original file
.B |||||||
.I original lines from the patch
.B =======
.I new lines from the patch
.B >>>>>>>
.RE
.fi
.IP "" 3
The optional argument of \fB\*=merge\fP determines the output format for
conflicts: the diff3 format shows the \fB|||||||\fP section with the original
lines from the patch; in the merge format, this section is missing. The merge
format is the default.
This option implies \fB\*=forward\fP and does not take the
\fB--fuzz\fR=\fInum\fP option into account.
.TP
\fB\-n\fP or \fB\*=normal\fP
Interpret the patch file as a normal diff.
.TP
\fB\-N\fP or \fB\*=forward\fP
When a patch does not apply, patch usually checks if the patch looks like it
has been reversed. The \fB\*=forward\fP option prevents that.
See also
.BR \-R .
.TP
\fB\-o\fP \fIoutfile\fP or \fB\*=output=\fP\fIoutfile\fP
Send output to
.I outfile
instead of patching files in place.
Do not use this option if
.I outfile
is one of the files to be patched.
When \fIoutfile\fP is \fB\-\fP, send output to standard output, and send any
messages that would usually go to standard output to standard error.
.TP
\fB\-p\fP\fInum\fP or \fB\*=strip\fP\fB=\fP\fInum\fP
Strip the smallest prefix containing
.I num
leading slashes from each file name found in the patch file.
A sequence of one or more adjacent slashes is counted as a single slash.
This controls how file names found in the patch file are treated, in case
you keep your files in a different directory than the person who sent
out the patch.
For example, supposing the file name in the patch file was
.Sp
.RS
\fB/u/howard/src/blurfl/blurfl.c\fP
.RE
.Sp
setting
.B \-p0
gives the entire file name unmodified,
.B \-p1
gives
.Sp
.RS
\fBu/howard/src/blurfl/blurfl.c\fP
.RE
.Sp
without the leading slash,
.B \-p4
gives
.Sp
.RS
\fBblurfl/blurfl.c\fP
.RE
.Sp
and not specifying
.B \-p
at all just gives you \fBblurfl.c\fP.
Whatever you end up with is looked for either in the current directory,
or the directory specified by the
.B \-d
option.
.TP
.B \*=posix
Conform more strictly to the \s-1POSIX\s0 standard, as follows.
.RS
.TP 3
.B " \(bu"
Take the first existing file from the list (old, new, index)
when intuiting file names from diff headers.
.TP
.B " \(bu"
Do not remove files that are empty after patching.
.TP
.B " \(bu"
Do not ask whether to get files from \s-1RCS\s0, ClearCase, Perforce,
or \s-1SCCS\s0.
.TP
.B " \(bu"
Require that all options precede the files in the command line.
.TP
.B " \(bu"
Do not backup files when there is a mismatch.
.RE
.TP
.BI \*=quoting\-style= word
Use style
.I word
to quote output names.
The
.I word
should be one of the following:
.RS
.TP
.B literal
Output names as-is.
.TP
.B shell
Quote names for the shell if they contain shell metacharacters or would
cause ambiguous output.
.TP
.B shell-always
Quote names for the shell, even if they would normally not require quoting.
.TP
.B c
Quote names as for a C language string.
.TP
.B escape
Quote as with
.B c
except omit the surrounding double-quote characters.
.LP
You can specify the default value of the
.B \*=quoting\-style
option with the environment variable
.BR QUOTING_STYLE .
If that environment variable is not set, the default value is
.BR shell .
.RE
.TP
\fB\-r\fP \fIrejectfile\fP or \fB\*=reject\-file=\fP\fIrejectfile\fP
Put rejects into
.I rejectfile
instead of the default
.B \&.rej
file. When \fIrejectfile\fP is \fB\-\fP, discard rejects.
.TP
\fB\-R\fP or \fB\*=reverse\fP
Assume that this patch was created with the old and new files swapped.
(Yes, I'm afraid that does happen occasionally, human nature being what it
is.)
.B patch
attempts to swap each hunk around before applying it.
Rejects come out in the swapped format.
The
.B \-R
option does not work with
.B ed
diff scripts because there is too little
information to reconstruct the reverse operation.
.Sp
If the first hunk of a patch fails,
.B patch
reverses the hunk to see if it can be applied that way.
If it can, you are asked if you want to have the
.B \-R
option set.
If it can't, the patch continues to be applied normally.
(Note: this method cannot detect a reversed patch if it is a normal diff
and if the first command is an append (i.e. it should have been a delete)
since appends always succeed, due to the fact that a null context matches
anywhere.
Luckily, most patches add or change lines rather than delete them, so most
reversed normal diffs begin with a delete, which fails, triggering
the heuristic.)
.TP
\fB\*=read\-only=\fP\fIbehavior\fP
Behave as requested when trying to modify a read-only file: \fBignore\fP the
potential problem, \fBwarn\fP about it (the default), or \fBfail\fP.
.TP
\fB\*=reject\-format=\fP\fIformat\fP
Produce reject files in the specified \fIformat\fP (either \fBcontext\fP or
\fBunified\fP). Without this option, rejected hunks come out in unified diff
format if the input patch was of that format, otherwise in ordinary context
diff form.
.TP
\fB\-s\fP or \fB\*=silent\fP or \fB\*=quiet\fP
Work silently, unless an error occurs.
.TP
\fB\*=follow\-symlinks\fP
When looking for input files, follow symbolic links. Replaces the symbolic
links, instead of modifying the files the symbolic links point to. Git-style
patches to symbolic links will no longer apply. This option exists for
backwards compatibility with previous versions of patch; its use is
discouraged.
.TP
\fB\-t\fP or \fB\*=batch\fP
Suppress questions like
.BR \-f ,
but make some different assumptions:
skip patches whose headers do not contain file names (the same as \fB\-f\fP);
skip patches for which the file has the wrong version for the
.B Prereq:\&
line
in the patch; and assume that patches are reversed if they look like
they are.
.TP
\fB\-T\fP or \fB\*=set\-time\fP
Set the modification and access times of patched files from time stamps
given in context diff headers. Unless specified in the time stamps,
assume that the context diff headers use local time.
.Sp
Use of this option with time stamps that do not include time zones 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. Make sure that time stamps include time zones, or generate
patches with \s-1UTC\s0 and use the
.B \-Z
or
.B \*=set\-utc
option instead.
.TP
\fB\-u\fP or \fB\*=unified\fP
Interpret the patch file as a unified context diff.
.TP
\fB\-v\fP or \fB\*=version\fP
Print out
.BR patch 's
revision header and patch level, and exit.
.TP
\fB\-V\fP \fImethod\fP or \fB\*=version\-control=\fP\fImethod\fP
Use
.I method
to determine
backup file names. The method can also be given by the
.B PATCH_VERSION_CONTROL
(or, if that's not set, the
.BR VERSION_CONTROL )
environment variable, which is overridden by this option.
The method does not affect whether backup files are made;
it affects only the names of any backup files that are made.
.Sp
The value of
.I method
is like the \s-1GNU\s0
Emacs `version-control' variable;
.B patch
also recognizes synonyms that
are more descriptive. The valid values for
.I method
are (unique abbreviations are
accepted):
.RS
.TP 3
\fBexisting\fP or \fBnil\fP
Make numbered backups of files that already have them,
otherwise simple backups.
This is the default.
.TP
\fBnumbered\fP or \fBt\fP
Make numbered backups. The numbered backup file name for
.I F
is
.IB F .~ N ~
where
.I N
is the version number.
.TP
\fBsimple\fP or \fBnever\fP
Make simple backups.
The
.B \-B
or
.BR \*=prefix ,
.B \-Y
or
.BR \*=basename\-prefix ,
and
.B \-z
or
.BR \*=suffix
options specify the simple backup file name.
If none of these options are given, then a simple backup suffix is used;
it is the value of the
.B SIMPLE_BACKUP_SUFFIX
environment variable if set, and is
.B \&.orig
otherwise.
.PP
With numbered or simple backups,
if the backup file name is too long, the backup suffix
.B ~
is used instead; if even appending
.B ~
would make the name too long, then
.B ~
replaces the last character of the file name.
.RE
.TP
\fB\*=verbose\fP
Output extra information about the work being done.
.TP
\fB\-x\fP \fInum\fP or \fB\*=debug=\fP\fInum\fP
Set internal debugging flags of interest only to
.B patch
patchers.
.TP
\fB\-Y\fP \fIpref\fP or \fB\*=basename\-prefix=\fP\fIpref\fP
Use the
.B simple
method to determine backup file names (see the
.BI "\-V " method
or
.BI "\*=version\-control " method
option), and prefix
.I pref
to the basename of a file name when generating its backup file name.
For example, with
.B "\-Y\ .del/"
the simple backup file name for
.B src/patch/util.c
is
.BR src/patch/.del/util.c .
.TP
\fB\-z\fP \fIsuffix\fP or \fB\*=suffix=\fP\fIsuffix\fP
Use the
.B simple
method to determine backup file names (see the
.BI "\-V " method
or
.BI "\*=version\-control " method
option), and use
.I suffix
as the suffix.
For example, with
.B "\-z\ -"
the backup file name for
.B src/patch/util.c
is
.BR src/patch/util.c- .
.TP
\fB\-Z\fP or \fB\*=set\-utc\fP
Set the modification and access times of patched files from time stamps
given in context diff headers. Unless specified in the time stamps,
assume that the context diff headers use Coordinated Universal Time
(\s-1UTC\s0, often known as \s-1GMT\s0). Also see the
.B \-T
or
.B \*=set\-time
option.
.Sp
The
.B \-Z
or
.B \*=set\-utc
and
.B \-T
or
.B \*=set\-time
options normally refrain from setting a file's time if the file's original time
does not match the time given in the patch header, or if its
contents do not match the patch exactly. However, if the
.B \-f
or
.B \*=force
option is given, the file time is set regardless.
.Sp
Due to the limitations of
.B diff
output format, these options cannot update the times of files whose
contents have not changed. Also, if you use these options, you should remove
(e.g. with
.BR "make\ clean" )
all files that depend on the patched files, so that later invocations of
.B make
do not get confused by the patched files' times.
.SH ENVIRONMENT
.TP 3
.B PATCH_GET
This specifies whether
.B patch
gets missing or read-only files from \s-1RCS\s0, ClearCase, Perforce,
or \s-1SCCS\s0
by default; see the
.B \-g
or
.B \*=get
option.
.TP
.B POSIXLY_CORRECT
If set,
.B patch
conforms more strictly to the \s-1POSIX\s0 standard by default:
see the
.B \*=posix
option.
.TP
.B QUOTING_STYLE
Default value of the
.B \*=quoting\-style
option.
.TP
.B SIMPLE_BACKUP_SUFFIX
Extension to use for simple backup file names instead of
.BR \&.orig .
.TP
\fBTMPDIR\fP, \fBTMP\fP, \fBTEMP\fP
Directory to put temporary files in;
.B patch
uses the first environment variable in this list that is set.
If none are set, the default is system-dependent;
it is normally
.B /tmp
on Unix hosts.
.TP
\fBVERSION_CONTROL\fP or \fBPATCH_VERSION_CONTROL\fP
Selects version control style; see the
.B \-v
or
.B \*=version\-control
option.
.SH FILES
.TP 3
.IB $TMPDIR "/p*"
temporary files
.TP
.B /dev/tty
controlling terminal; used to get answers to questions asked of the user
.SH "SEE ALSO"
.BR diff (1),
.BR ed (1),
.BR merge (1).
.Sp
Marshall T. Rose and Einar A. Stefferud,
Proposed Standard for Message Encapsulation,
Internet RFC 934 <URL:ftp://ftp.isi.edu/in-notes/rfc934.txt> (1985-01).
.SH "NOTES FOR PATCH SENDERS"
There are several things you should bear in mind if you are going to
be sending out patches.
.PP
Create your patch systematically.
A good method is the command
.BI "diff\ \-Naur\ " "old\ new"
where
.I old
and
.I new
identify the old and new directories.
The names
.I old
and
.I new
should not contain any slashes.
The
.B diff
command's headers should have dates
and times in Universal Time using traditional Unix format,
so that patch recipients can use the
.B \-Z
or
.B \*=set\-utc
option.
Here is an example command, using Bourne shell syntax:
.Sp
.RS
\fBLC_ALL=C TZ=UTC0 diff \-Naur gcc\-2.7 gcc\-2.8\fP
.RE
.PP
Tell your recipients how to apply the patch
by telling them which directory to
.B cd
to, and which
.B patch
options to use. The option string
.B "\-Np1"
is recommended.
Test your procedure by pretending to be a recipient and applying
your patch to a copy of the original files.
.PP
You can save people a lot of grief by keeping a
.B patchlevel.h
file which is patched to increment the patch level
as the first diff in the patch file you send out.
If you put a
.B Prereq:\&
line in with the patch, it won't let them apply
patches out of order without some warning.
.PP
You can create a file by sending out a diff that compares
.B /dev/null
or an empty file dated the Epoch (1970-01-01 00:00:00 \s-1UTC\s0)
to the file you want to create.
This only works if the file you want to create doesn't exist already in
the target directory.
Conversely, you can remove a file by sending out a context diff that compares
the file to be deleted with an empty file dated the Epoch.
The file will be removed unless
.B patch
is conforming to \s-1POSIX\s0 and the
.B \-E
or
.B \*=remove\-empty\-files
option is not given.
An easy way to generate patches that create and remove files
is to use \s-1GNU\s0
.BR diff 's
.B \-N
or
.B \*=new\-file
option.
.PP
If the recipient is supposed to use the
.BI \-p N
option, do not send output that looks like this:
.Sp
.RS
.ft CW
.ne 3
diff \-Naur v2.0.29/prog/README prog/README
.br
\-\^\-\^\- v2.0.29/prog/README Mon Mar 10 15:13:12 1997
.br
+\^+\^+ prog/README Mon Mar 17 14:58:22 1997
.ft
.RE
.Sp
because the two file names have different numbers of slashes,
and different versions of
.B patch
interpret the file names differently.
To avoid confusion, send output that looks like this instead:
.Sp
.RS
.ft CW
.ne 3
diff \-Naur v2.0.29/prog/README v2.0.30/prog/README
.br
\-\^\-\^\- v2.0.29/prog/README Mon Mar 10 15:13:12 1997
.br
+\^+\^+ v2.0.30/prog/README Mon Mar 17 14:58:22 1997
.ft
.RE
.Sp
.PP
Avoid sending patches that compare backup file names like
.BR README.orig ,
since this might confuse
.B patch
into patching a backup file instead of the real file.
Instead, send patches that compare the same base file names
in different directories, e.g.\&
.B old/README
and
.BR new/README .
.PP
Take care not to send out reversed patches, since it makes people wonder
whether they already applied the patch.
.PP
Try not to have your patch modify derived files
(e.g. the file
.B configure
where there is a line
.B "configure: configure.in"
in your makefile), since the recipient should be
able to regenerate the derived files anyway.
If you must send diffs of derived files,
generate the diffs using \s-1UTC\s0,
have the recipients apply the patch with the
.B \-Z
or
.B \*=set\-utc
option, and have them remove any unpatched files that depend on patched files
(e.g. with
.BR "make\ clean" ).
.PP
While you may be able to get away with putting 582 diff listings into
one file, it may be wiser to group related patches into separate files in
case something goes haywire.
.SH DIAGNOSTICS
Diagnostics generally indicate that
.B patch
couldn't parse your patch file.
.PP
If the
.B \*=verbose
option is given, the message
.B Hmm.\|.\|.\&
indicates that there is unprocessed text in
the patch file and that
.B patch
is attempting to intuit whether there is a patch in that text and, if so,
what kind of patch it is.
.PP
.BR patch 's
exit status is
0 if all hunks are applied successfully,
1 if some hunks cannot be applied or there were merge conflicts,
and 2 if there is more serious trouble.
When applying a set of patches in a loop it behooves you to check this
exit status so you don't apply a later patch to a partially patched file.
.SH CAVEATS
Context diffs cannot reliably represent the creation or deletion of
empty files, empty directories, or special files such as symbolic links.
Nor can they represent changes to file metadata like ownership, permissions,
or whether one file is a hard link to another.
If changes like these are also required, separate instructions
(e.g. a shell script) to accomplish them should accompany the patch.
.PP
.B patch
cannot tell if the line numbers are off in an
.B ed
script, and can detect
bad line numbers in a normal diff only when it finds a change or deletion.
A context diff using fuzz factor 3 may have the same problem.
You should probably do
a context diff in these cases to see if the changes made sense.
Of course, compiling without errors is a pretty good indication that the patch
worked, but not always.
.PP
.B patch
usually produces the correct results, even when it has to do a lot of
guessing.
However, the results are guaranteed to be correct only when the patch is
applied to exactly the same version of the file that the patch was
generated from.
.SH "COMPATIBILITY ISSUES"
The \s-1POSIX\s0 standard specifies behavior that differs from
.BR patch 's
traditional behavior.
You should be aware of these differences if you must interoperate with
.B patch
versions 2.1 and earlier, which do not conform to \s-1POSIX\s0.
.TP 3
.B " \(bu"
In traditional
.BR patch ,
the
.B \-p
option's operand was optional, and a bare
.B \-p
was equivalent to
.BR \-p0.
The
.B \-p
option now requires an operand, and
.B "\-p\ 0"
is now equivalent to
.BR \-p0 .
For maximum compatibility, use options like
.B \-p0
and
.BR \-p1 .
.Sp
Also,
traditional
.B patch
simply counted slashes when stripping path prefixes;
.B patch
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
.B //
in file names.
.TP
.B " \(bu"
In traditional
.BR patch ,
backups were enabled by default.
This behavior is now enabled with the
.B \-b
or
.B \*=backup
option.
.Sp
Conversely, in \s-1POSIX\s0
.BR patch ,
backups are never made, even when there is a mismatch.
In \s-1GNU\s0
.BR patch ,
this behavior is enabled with the
.B \*=no\-backup\-if\-mismatch
option, or by conforming to \s-1POSIX\s0 with the
.B \*=posix
option or by setting the
.B POSIXLY_CORRECT
environment variable.
.Sp
The
.BI \-b "\ suffix"
option
of traditional
.B patch
is equivalent to the
.BI "\-b\ \-z" "\ suffix"
options of \s-1GNU\s0
.BR patch .
.TP
.B " \(bu"
Traditional
.B patch
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 \s-1POSIX\s0, and had a few gotchas.
Now
.B patch
uses a different, equally complicated (but better documented) method
that is optionally \s-1POSIX\s0-conforming; we hope it has
fewer gotchas. The two methods are compatible if the
file names in the context diff header and the
.B Index:\&
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.
.TP
.B " \(bu"
When traditional
.B patch
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,
.BR /dev/tty ,
and standard input.
Now
.B patch
sends questions to standard output and gets answers from
.BR /dev/tty .
Defaults for some answers have been changed so that
.B patch
never goes into an infinite loop when using default answers.
.TP
.B " \(bu"
Traditional
.B patch
exited with a status value that counted the number of bad hunks,
or with status 1 if there was real trouble.
Now
.B patch
exits with status 1 if some hunks failed,
or with 2 if there was real trouble.
.TP
.B " \(bu"
Limit yourself to the following options when sending instructions
meant to be executed by anyone running \s-1GNU\s0
.BR patch ,
traditional
.BR patch ,
or a
.B patch
that conforms to \s-1POSIX\s0.
Spaces are significant in the following list, and operands are required.
.Sp
.nf
.in +3
.ne 11
.B \-c
.BI \-d " dir"
.BI \-D " define"
.B \-e
.B \-l
.B \-n
.B \-N
.BI \-o " outfile"
.BI \-p num
.B \-R
.BI \-r " rejectfile"
.in
.fi
.SH BUGS
Please report bugs via email to
.BR <bug-patch@gnu.org> .
.PP
If code has been duplicated (for instance with
\fB#ifdef OLDCODE\fP .\|.\|. \fB#else .\|.\|. #endif\fP),
.B patch
is incapable of patching both versions, and, if it works at all, will likely
patch the wrong one, and tell you that it succeeded to boot.
.PP
If you apply a patch you've already applied,
.B patch
thinks it is a reversed patch, and offers to un-apply the patch.
This could be construed as a feature.
.PP
Computing how to merge a hunk is significantly harder than using the standard
fuzzy algorithm. Bigger hunks, more context, a bigger offset from the
original location, and a worse match all slow the algorithm down.
.SH COPYING
Copyright
.ie t \(co
.el (C)
1984, 1985, 1986, 1988 Larry Wall.
.br
Copyright
.ie t \(co
.el (C)
1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
2000, 2001, 2002, 2009 Free Software Foundation, Inc.
.PP
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
.PP
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the
entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
.PP
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that this permission notice may be included in
translations approved by the copyright holders instead of in
the original English.
.SH AUTHORS
Larry Wall wrote the original version of
.BR patch .
Paul Eggert removed
.BR patch 's
arbitrary limits; added support for binary files,
setting file times, and deleting files;
and made it conform better to \s-1POSIX\s0.
Other contributors include Wayne Davison, who added unidiff support,
and David MacKenzie, who added configuration and backup support.
Andreas Gr\[:u]nbacher added support for merging.
|