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