]>
Commit | Line | Data |
---|---|---|
d0587fd5 JH |
1 | git-apply(1) |
2 | ============ | |
d0587fd5 JH |
3 | |
4 | NAME | |
5 | ---- | |
c3f0baac | 6 | git-apply - Apply a patch on a git index file and a working tree |
d0587fd5 JH |
7 | |
8 | ||
9 | SYNOPSIS | |
10 | -------- | |
353ce815 | 11 | [verse] |
b1889c36 | 12 | 'git apply' [--stat] [--numstat] [--summary] [--check] [--index] |
f26c4940 | 13 | [--apply] [--no-add] [--build-fake-ancestor=<file>] [-R | --reverse] |
0b9a9dd0 | 14 | [--allow-binary-replacement | --binary] [--reject] [-z] |
c14b9d1e | 15 | [-pNUM] [-CNUM] [--inaccurate-eof] [--recount] [--cached] |
91af7ae5 | 16 | [--whitespace=<nowarn|warn|fix|error|error-all>] |
6ecb1ee2 JH |
17 | [--exclude=PATH] [--include=PATH] [--directory=<root>] |
18 | [--verbose] [<patch>...] | |
d0587fd5 JH |
19 | |
20 | DESCRIPTION | |
21 | ----------- | |
0979c106 | 22 | Reads supplied 'diff' output and applies it on a git index file |
d0587fd5 JH |
23 | and a work tree. |
24 | ||
25 | OPTIONS | |
26 | ------- | |
12dd6e8c JH |
27 | <patch>...:: |
28 | The files to read patch from. '-' can be used to read | |
29 | from the standard input. | |
d0587fd5 | 30 | |
d0587fd5 JH |
31 | --stat:: |
32 | Instead of applying the patch, output diffstat for the | |
12dd6e8c | 33 | input. Turns off "apply". |
d0587fd5 | 34 | |
7d8b7c21 JH |
35 | --numstat:: |
36 | Similar to \--stat, but shows number of added and | |
37 | deleted lines in decimal notation and pathname without | |
2f89543e JH |
38 | abbreviation, to make it more machine friendly. For |
39 | binary files, outputs two `-` instead of saying | |
40 | `0 0`. Turns off "apply". | |
7d8b7c21 | 41 | |
d0587fd5 JH |
42 | --summary:: |
43 | Instead of applying the patch, output a condensed | |
44 | summary of information obtained from git diff extended | |
45 | headers, such as creations, renames and mode changes. | |
12dd6e8c | 46 | Turns off "apply". |
d0587fd5 JH |
47 | |
48 | --check:: | |
49 | Instead of applying the patch, see if the patch is | |
50 | applicable to the current work tree and/or the index | |
12dd6e8c | 51 | file and detects errors. Turns off "apply". |
d0587fd5 JH |
52 | |
53 | --index:: | |
54 | When --check is in effect, or when applying the patch | |
55 | (which is the default when none of the options that | |
56 | disables it is in effect), make sure the patch is | |
57 | applicable to what the current index file records. If | |
58 | the file to be patched in the work tree is not | |
59 | up-to-date, it is flagged as an error. This flag also | |
60 | causes the index file to be updated. | |
61 | ||
5684ed6d JF |
62 | --cached:: |
63 | Apply a patch without touching the working tree. Instead, take the | |
64 | cached data, apply the patch, and store the result in the index, | |
65 | without using the working tree. This implies '--index'. | |
66 | ||
f26c4940 | 67 | --build-fake-ancestor=<file>:: |
ba020ef5 | 68 | Newer 'git-diff' output has embedded 'index information' |
d88156e9 JH |
69 | for each blob to help identify the original version that |
70 | the patch applies to. When this flag is given, and if | |
7a988699 JS |
71 | the original versions of the blobs is available locally, |
72 | builds a temporary index containing those blobs. | |
73 | + | |
74 | When a pure mode change is encountered (which has no index information), | |
75 | the information is read from the current index instead. | |
d88156e9 | 76 | |
3240240f SB |
77 | -R:: |
78 | --reverse:: | |
5684ed6d JF |
79 | Apply the patch in reverse. |
80 | ||
81 | --reject:: | |
ba020ef5 | 82 | For atomicity, 'git-apply' by default fails the whole patch and |
5684ed6d JF |
83 | does not touch the working tree when some of the hunks |
84 | do not apply. This option makes it apply | |
b32d37a3 | 85 | the parts of the patch that are applicable, and leave the |
8938045a | 86 | rejected hunks in corresponding *.rej files. |
5684ed6d | 87 | |
d88156e9 JH |
88 | -z:: |
89 | When showing the index information, do not munge paths, | |
90 | but use NUL terminated machine readable format. Without | |
91 | this flag, the pathnames output will have TAB, LF, and | |
92 | backslash characters replaced with `\t`, `\n`, and `\\`, | |
93 | respectively. | |
94 | ||
e36f8b60 DB |
95 | -p<n>:: |
96 | Remove <n> leading slashes from traditional diff paths. The | |
97 | default is 1. | |
98 | ||
47495887 EB |
99 | -C<n>:: |
100 | Ensure at least <n> lines of surrounding context match before | |
101 | and after each change. When fewer lines of surrounding | |
74237d62 | 102 | context exist they all must match. By default no context is |
47495887 EB |
103 | ever ignored. |
104 | ||
f58bb6fb | 105 | --unidiff-zero:: |
ba020ef5 | 106 | By default, 'git-apply' expects that the patch being |
f58bb6fb JF |
107 | applied is a unified diff with at least one line of context. |
108 | This provides good safety measures, but breaks down when | |
109 | applying a diff generated with --unified=0. To bypass these | |
110 | checks use '--unidiff-zero'. | |
111 | + | |
112 | Note, for the reasons stated above usage of context-free patches are | |
113 | discouraged. | |
114 | ||
12dd6e8c | 115 | --apply:: |
5684ed6d | 116 | If you use any of the options marked "Turns off |
ba020ef5 | 117 | 'apply'" above, 'git-apply' reads and outputs the |
12dd6e8c JH |
118 | information you asked without actually applying the |
119 | patch. Give this flag after those flags to also apply | |
120 | the patch. | |
121 | ||
e433705d JH |
122 | --no-add:: |
123 | When applying a patch, ignore additions made by the | |
71a9883d | 124 | patch. This can be used to extract the common part between |
2fd02c92 | 125 | two files by first running 'diff' on them and applying |
e433705d JH |
126 | the result with this option, which would apply the |
127 | deletion part but not addition part. | |
d0587fd5 | 128 | |
3240240f SB |
129 | --allow-binary-replacement:: |
130 | --binary:: | |
2b6eef94 JH |
131 | Historically we did not allow binary patch applied |
132 | without an explicit permission from the user, and this | |
133 | flag was the way to do so. Currently we always allow binary | |
134 | patch application, so this is a no-op. | |
27dedf0c | 135 | |
5684ed6d JF |
136 | --exclude=<path-pattern>:: |
137 | Don't apply changes to files matching the given path pattern. This can | |
138 | be useful when importing patchsets, where you want to exclude certain | |
139 | files or directories. | |
140 | ||
6ecb1ee2 JH |
141 | --include=<path-pattern>:: |
142 | Apply changes to files matching the given path pattern. This can | |
143 | be useful when importing patchsets, where you want to include certain | |
144 | files or directories. | |
145 | + | |
146 | When --exclude and --include patterns are used, they are examined in the | |
147 | order they appear on the command line, and the first match determines if a | |
148 | patch to each path is used. A patch to a path that does not match any | |
149 | include/exclude pattern is used by default if there is no include pattern | |
150 | on the command line, and ignored if there is any include pattern. | |
151 | ||
91af7ae5 JH |
152 | --whitespace=<action>:: |
153 | When applying a patch, detect a new or modified line that has | |
154 | whitespace errors. What are considered whitespace errors is | |
155 | controlled by `core.whitespace` configuration. By default, | |
156 | trailing whitespaces (including lines that solely consist of | |
157 | whitespaces) and a space character that is immediately followed | |
158 | by a tab character inside the initial indent of the line are | |
159 | considered whitespace errors. | |
160 | + | |
161 | By default, the command outputs warning messages but applies the patch. | |
eb006ccf | 162 | When `git-apply` is used for statistics and not applying a |
91af7ae5 JH |
163 | patch, it defaults to `nowarn`. |
164 | + | |
165 | You can use different `<action>` to control this | |
166 | behavior: | |
8273c79a JH |
167 | + |
168 | * `nowarn` turns off the trailing whitespace warning. | |
169 | * `warn` outputs warnings for a few such errors, but applies the | |
91af7ae5 JH |
170 | patch as-is (default). |
171 | * `fix` outputs warnings for a few such errors, and applies the | |
172 | patch after fixing them (`strip` is a synonym --- the tool | |
173 | used to consider only trailing whitespaces as errors, and the | |
174 | fix involved 'stripping' them, but modern gits do more). | |
8273c79a JH |
175 | * `error` outputs warnings for a few such errors, and refuses |
176 | to apply the patch. | |
177 | * `error-all` is similar to `error` but shows all errors. | |
8273c79a | 178 | |
f847c07b | 179 | --inaccurate-eof:: |
0979c106 | 180 | Under certain circumstances, some versions of 'diff' do not correctly |
5684ed6d | 181 | detect a missing new-line at the end of the file. As a result, patches |
0979c106 | 182 | created by such 'diff' programs do not record incomplete lines |
5684ed6d JF |
183 | correctly. This option adds support for applying such patches by |
184 | working around this bug. | |
185 | ||
3240240f SB |
186 | -v:: |
187 | --verbose:: | |
5684ed6d JF |
188 | Report progress to stderr. By default, only a message about the |
189 | current patch being applied will be printed. This option will cause | |
190 | additional information to be reported. | |
8273c79a | 191 | |
c14b9d1e JS |
192 | --recount:: |
193 | Do not trust the line counts in the hunk headers, but infer them | |
194 | by inspecting the patch (e.g. after editing the patch without | |
195 | adjusting the hunk headers appropriately). | |
196 | ||
f5563887 | 197 | --directory=<root>:: |
c4730f35 JS |
198 | Prepend <root> to all filenames. If a "-p" argument was passed, too, |
199 | it is applied before prepending the new root. | |
f5563887 JH |
200 | + |
201 | For example, a patch that talks about updating `a/git-gui.sh` to `b/git-gui.sh` | |
202 | can be applied to the file in the working tree `modules/git-gui/git-gui.sh` by | |
203 | running `git apply --directory=modules/git-gui`. | |
c4730f35 | 204 | |
8273c79a JH |
205 | Configuration |
206 | ------------- | |
207 | ||
208 | apply.whitespace:: | |
209 | When no `--whitespace` flag is given from the command | |
210 | line, this configuration item is used as the default. | |
211 | ||
e06c5a6c SV |
212 | Submodules |
213 | ---------- | |
ba020ef5 | 214 | If the patch contains any changes to submodules then 'git-apply' |
e06c5a6c SV |
215 | treats these changes as follows. |
216 | ||
217 | If --index is specified (explicitly or implicitly), then the submodule | |
218 | commits must match the index exactly for the patch to apply. If any | |
219 | of the submodules are checked-out, then these check-outs are completely | |
220 | ignored, i.e., they are not required to be up-to-date or clean and they | |
221 | are not updated. | |
222 | ||
223 | If --index is not specified, then the submodule commits in the patch | |
224 | are ignored and only the absence of presence of the corresponding | |
225 | subdirectory is checked and (if possible) updated. | |
8273c79a | 226 | |
d0587fd5 JH |
227 | Author |
228 | ------ | |
229 | Written by Linus Torvalds <torvalds@osdl.org> | |
230 | ||
231 | Documentation | |
232 | -------------- | |
233 | Documentation by Junio C Hamano | |
234 | ||
235 | GIT | |
236 | --- | |
9e1f0a85 | 237 | Part of the linkgit:git[1] suite |