]>
Commit | Line | Data |
---|---|---|
d0587fd5 JH |
1 | git-apply(1) |
2 | ============ | |
d0587fd5 JH |
3 | |
4 | NAME | |
5 | ---- | |
72e9340c | 6 | git-apply - Apply patch on a git index file and a work tree |
d0587fd5 JH |
7 | |
8 | ||
9 | SYNOPSIS | |
10 | -------- | |
353ce815 JF |
11 | [verse] |
12 | 'git-apply' [--stat] [--numstat] [--summary] [--check] [--index] [--apply] | |
5684ed6d JF |
13 | [--no-add] [--index-info] [--allow-binary-replacement | --binary] |
14 | [-R | --reverse] [--reject] [-z] [-pNUM] [-CNUM] [--inaccurate-eof] | |
15 | [--whitespace=<nowarn|warn|error|error-all|strip>] [--exclude=PATH] | |
16 | [--cached] [--verbose] [<patch>...] | |
d0587fd5 JH |
17 | |
18 | DESCRIPTION | |
19 | ----------- | |
f73ae1fc | 20 | Reads supplied diff output and applies it on a git index file |
d0587fd5 JH |
21 | and a work tree. |
22 | ||
23 | OPTIONS | |
24 | ------- | |
12dd6e8c JH |
25 | <patch>...:: |
26 | The files to read patch from. '-' can be used to read | |
27 | from the standard input. | |
d0587fd5 | 28 | |
d0587fd5 JH |
29 | --stat:: |
30 | Instead of applying the patch, output diffstat for the | |
12dd6e8c | 31 | input. Turns off "apply". |
d0587fd5 | 32 | |
7d8b7c21 JH |
33 | --numstat:: |
34 | Similar to \--stat, but shows number of added and | |
35 | deleted lines in decimal notation and pathname without | |
36 | abbreviation, to make it more machine friendly. Turns | |
37 | off "apply". | |
38 | ||
d0587fd5 JH |
39 | --summary:: |
40 | Instead of applying the patch, output a condensed | |
41 | summary of information obtained from git diff extended | |
42 | headers, such as creations, renames and mode changes. | |
12dd6e8c | 43 | Turns off "apply". |
d0587fd5 JH |
44 | |
45 | --check:: | |
46 | Instead of applying the patch, see if the patch is | |
47 | applicable to the current work tree and/or the index | |
12dd6e8c | 48 | file and detects errors. Turns off "apply". |
d0587fd5 JH |
49 | |
50 | --index:: | |
51 | When --check is in effect, or when applying the patch | |
52 | (which is the default when none of the options that | |
53 | disables it is in effect), make sure the patch is | |
54 | applicable to what the current index file records. If | |
55 | the file to be patched in the work tree is not | |
56 | up-to-date, it is flagged as an error. This flag also | |
57 | causes the index file to be updated. | |
58 | ||
5684ed6d JF |
59 | --cached:: |
60 | Apply a patch without touching the working tree. Instead, take the | |
61 | cached data, apply the patch, and store the result in the index, | |
62 | without using the working tree. This implies '--index'. | |
63 | ||
d88156e9 JH |
64 | --index-info:: |
65 | Newer git-diff output has embedded 'index information' | |
66 | for each blob to help identify the original version that | |
67 | the patch applies to. When this flag is given, and if | |
68 | the original version of the blob is available locally, | |
69 | outputs information about them to the standard output. | |
70 | ||
5684ed6d JF |
71 | -R, --reverse:: |
72 | Apply the patch in reverse. | |
73 | ||
74 | --reject:: | |
75 | For atomicity, gitlink:git-apply[1] by default fails the whole patch and | |
76 | does not touch the working tree when some of the hunks | |
77 | do not apply. This option makes it apply | |
b32d37a3 | 78 | the parts of the patch that are applicable, and leave the |
8938045a | 79 | rejected hunks in corresponding *.rej files. |
5684ed6d | 80 | |
d88156e9 JH |
81 | -z:: |
82 | When showing the index information, do not munge paths, | |
83 | but use NUL terminated machine readable format. Without | |
84 | this flag, the pathnames output will have TAB, LF, and | |
85 | backslash characters replaced with `\t`, `\n`, and `\\`, | |
86 | respectively. | |
87 | ||
e36f8b60 DB |
88 | -p<n>:: |
89 | Remove <n> leading slashes from traditional diff paths. The | |
90 | default is 1. | |
91 | ||
47495887 EB |
92 | -C<n>:: |
93 | Ensure at least <n> lines of surrounding context match before | |
94 | and after each change. When fewer lines of surrounding | |
74237d62 | 95 | context exist they all must match. By default no context is |
47495887 EB |
96 | ever ignored. |
97 | ||
f58bb6fb JF |
98 | --unidiff-zero:: |
99 | By default, gitlink:git-apply[1] expects that the patch being | |
100 | applied is a unified diff with at least one line of context. | |
101 | This provides good safety measures, but breaks down when | |
102 | applying a diff generated with --unified=0. To bypass these | |
103 | checks use '--unidiff-zero'. | |
104 | + | |
105 | Note, for the reasons stated above usage of context-free patches are | |
106 | discouraged. | |
107 | ||
12dd6e8c | 108 | --apply:: |
5684ed6d JF |
109 | If you use any of the options marked "Turns off |
110 | 'apply'" above, gitlink:git-apply[1] reads and outputs the | |
12dd6e8c JH |
111 | information you asked without actually applying the |
112 | patch. Give this flag after those flags to also apply | |
113 | the patch. | |
114 | ||
e433705d JH |
115 | --no-add:: |
116 | When applying a patch, ignore additions made by the | |
117 | patch. This can be used to extract common part between | |
118 | two files by first running `diff` on them and applying | |
119 | the result with this option, which would apply the | |
120 | deletion part but not addition part. | |
d0587fd5 | 121 | |
5684ed6d | 122 | --allow-binary-replacement, --binary:: |
2b6eef94 JH |
123 | Historically we did not allow binary patch applied |
124 | without an explicit permission from the user, and this | |
125 | flag was the way to do so. Currently we always allow binary | |
126 | patch application, so this is a no-op. | |
27dedf0c | 127 | |
5684ed6d JF |
128 | --exclude=<path-pattern>:: |
129 | Don't apply changes to files matching the given path pattern. This can | |
130 | be useful when importing patchsets, where you want to exclude certain | |
131 | files or directories. | |
132 | ||
8273c79a JH |
133 | --whitespace=<option>:: |
134 | When applying a patch, detect a new or modified line | |
135 | that ends with trailing whitespaces (this includes a | |
136 | line that solely consists of whitespaces). By default, | |
137 | the command outputs warning messages and applies the | |
138 | patch. | |
5684ed6d | 139 | When gitlink:git-apply[1] is used for statistics and not applying a |
8273c79a JH |
140 | patch, it defaults to `nowarn`. |
141 | You can use different `<option>` to control this | |
abda1ef5 | 142 | behavior: |
8273c79a JH |
143 | + |
144 | * `nowarn` turns off the trailing whitespace warning. | |
145 | * `warn` outputs warnings for a few such errors, but applies the | |
146 | patch (default). | |
147 | * `error` outputs warnings for a few such errors, and refuses | |
148 | to apply the patch. | |
149 | * `error-all` is similar to `error` but shows all errors. | |
150 | * `strip` outputs warnings for a few such errors, strips out the | |
151 | trailing whitespaces and applies the patch. | |
152 | ||
f847c07b | 153 | --inaccurate-eof:: |
5684ed6d JF |
154 | Under certain circumstances, some versions of diff do not correctly |
155 | detect a missing new-line at the end of the file. As a result, patches | |
156 | created by such diff programs do not record incomplete lines | |
157 | correctly. This option adds support for applying such patches by | |
158 | working around this bug. | |
159 | ||
160 | --verbose:: | |
161 | Report progress to stderr. By default, only a message about the | |
162 | current patch being applied will be printed. This option will cause | |
163 | additional information to be reported. | |
8273c79a JH |
164 | |
165 | Configuration | |
166 | ------------- | |
167 | ||
168 | apply.whitespace:: | |
169 | When no `--whitespace` flag is given from the command | |
170 | line, this configuration item is used as the default. | |
171 | ||
172 | ||
d0587fd5 JH |
173 | Author |
174 | ------ | |
175 | Written by Linus Torvalds <torvalds@osdl.org> | |
176 | ||
177 | Documentation | |
178 | -------------- | |
179 | Documentation by Junio C Hamano | |
180 | ||
181 | GIT | |
182 | --- | |
a7154e91 | 183 | Part of the gitlink:git[7] suite |
d0587fd5 | 184 |