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