6 git-apply - Apply a patch on a git index file and/or a working tree
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>...]
23 Reads supplied 'diff' output and applies it on a git index file
29 The files to read the patch from. '-' can be used to read
30 from the standard input.
33 Instead of applying the patch, output diffstat for the
34 input. Turns off "apply".
37 Similar to \--stat, but shows the number of added and
38 deleted lines in decimal notation and the pathname without
39 abbreviation, to make it more machine friendly. For
40 binary files, outputs two `-` instead of saying
41 `0 0`. Turns off "apply".
44 Instead of applying the patch, output a condensed
45 summary of information obtained from git diff extended
46 headers, such as creations, renames and mode changes.
50 Instead of applying the patch, see if the patch is
51 applicable to the current work tree and/or the index
52 file and detects errors. Turns off "apply".
55 When --check is in effect, or when applying the patch
56 (which is the default when none of the options that
57 disables it is in effect), make sure the patch is
58 applicable to what the current index file records. If
59 the file to be patched in the work tree is not
60 up-to-date, it is flagged as an error. This flag also
61 causes the index file to be updated.
64 Apply a patch without touching the working tree. Instead take the
65 cached data, apply the patch, and store the result in the index
66 without using the working tree. This implies '--index'.
68 --build-fake-ancestor=<file>::
69 Newer 'git-diff' output has embedded 'index information'
70 for each blob to help identify the original version that
71 the patch applies to. When this flag is given, and if
72 the original versions of the blobs are available locally,
73 builds a temporary index containing those blobs.
75 When a pure mode change is encountered (which has no index information),
76 the information is read from the current index instead.
80 Apply the patch in reverse.
83 For atomicity, 'git-apply' by default fails the whole patch and
84 does not touch the working tree when some of the hunks
85 do not apply. This option makes it apply
86 the parts of the patch that are applicable, and leave the
87 rejected hunks in corresponding *.rej files.
90 When `--numstat` has been given, do not munge pathnames,
91 but use a NUL-terminated machine-readable format.
93 Without this option, each pathname output will have TAB, LF, double quotes,
94 and backslash characters replaced with `\t`, `\n`, `\"`, and `\\`,
95 respectively, and the pathname will be enclosed in double quotes if
96 any of those replacements occurred.
99 Remove <n> leading slashes from traditional diff paths. The
103 Ensure at least <n> lines of surrounding context match before
104 and after each change. When fewer lines of surrounding
105 context exist they all must match. By default no context is
109 By default, 'git-apply' expects that the patch being
110 applied is a unified diff with at least one line of context.
111 This provides good safety measures, but breaks down when
112 applying a diff generated with --unified=0. To bypass these
113 checks use '--unidiff-zero'.
115 Note, for the reasons stated above usage of context-free patches is
119 If you use any of the options marked "Turns off
120 'apply'" above, 'git-apply' reads and outputs the
121 requested information without actually applying the
122 patch. Give this flag after those flags to also apply
126 When applying a patch, ignore additions made by the
127 patch. This can be used to extract the common part between
128 two files by first running 'diff' on them and applying
129 the result with this option, which would apply the
130 deletion part but not the addition part.
132 --allow-binary-replacement::
134 Historically we did not allow binary patch applied
135 without an explicit permission from the user, and this
136 flag was the way to do so. Currently we always allow binary
137 patch application, so this is a no-op.
139 --exclude=<path-pattern>::
140 Don't apply changes to files matching the given path pattern. This can
141 be useful when importing patchsets, where you want to exclude certain
142 files or directories.
144 --include=<path-pattern>::
145 Apply changes to files matching the given path pattern. This can
146 be useful when importing patchsets, where you want to include certain
147 files or directories.
149 When --exclude and --include patterns are used, they are examined in the
150 order they appear on the command line, and the first match determines if a
151 patch to each path is used. A patch to a path that does not match any
152 include/exclude pattern is used by default if there is no include pattern
153 on the command line, and ignored if there is any include pattern.
155 --ignore-space-change::
156 --ignore-whitespace::
157 When applying a patch, ignore changes in whitespace in context
159 Context lines will preserve their whitespace, and they will not
160 undergo whitespace fixing regardless of the value of the
161 `--whitespace` option. New lines will still be fixed, though.
163 --whitespace=<action>::
164 When applying a patch, detect a new or modified line that has
165 whitespace errors. What are considered whitespace errors is
166 controlled by `core.whitespace` configuration. By default,
167 trailing whitespaces (including lines that solely consist of
168 whitespaces) and a space character that is immediately followed
169 by a tab character inside the initial indent of the line are
170 considered whitespace errors.
172 By default, the command outputs warning messages but applies the patch.
173 When `git-apply` is used for statistics and not applying a
174 patch, it defaults to `nowarn`.
176 You can use different `<action>` values to control this
179 * `nowarn` turns off the trailing whitespace warning.
180 * `warn` outputs warnings for a few such errors, but applies the
181 patch as-is (default).
182 * `fix` outputs warnings for a few such errors, and applies the
183 patch after fixing them (`strip` is a synonym --- the tool
184 used to consider only trailing whitespace characters as errors, and the
185 fix involved 'stripping' them, but modern gits do more).
186 * `error` outputs warnings for a few such errors, and refuses
188 * `error-all` is similar to `error` but shows all errors.
191 Under certain circumstances, some versions of 'diff' do not correctly
192 detect a missing new-line at the end of the file. As a result, patches
193 created by such 'diff' programs do not record incomplete lines
194 correctly. This option adds support for applying such patches by
195 working around this bug.
199 Report progress to stderr. By default, only a message about the
200 current patch being applied will be printed. This option will cause
201 additional information to be reported.
204 Do not trust the line counts in the hunk headers, but infer them
205 by inspecting the patch (e.g. after editing the patch without
206 adjusting the hunk headers appropriately).
209 Prepend <root> to all filenames. If a "-p" argument was also passed,
210 it is applied before prepending the new root.
212 For example, a patch that talks about updating `a/git-gui.sh` to `b/git-gui.sh`
213 can be applied to the file in the working tree `modules/git-gui/git-gui.sh` by
214 running `git apply --directory=modules/git-gui`.
219 apply.ignorewhitespace::
220 Set to 'change' if you want changes in whitespace to be ignored by default.
221 Set to one of: no, none, never, false if you want changes in
222 whitespace to be significant.
224 When no `--whitespace` flag is given from the command
225 line, this configuration item is used as the default.
229 If the patch contains any changes to submodules then 'git-apply'
230 treats these changes as follows.
232 If --index is specified (explicitly or implicitly), then the submodule
233 commits must match the index exactly for the patch to apply. If any
234 of the submodules are checked-out, then these check-outs are completely
235 ignored, i.e., they are not required to be up-to-date or clean and they
238 If --index is not specified, then the submodule commits in the patch
239 are ignored and only the absence or presence of the corresponding
240 subdirectory is checked and (if possible) updated.
244 Written by Linus Torvalds <torvalds@osdl.org>
248 Documentation by Junio C Hamano
252 Part of the linkgit:git[1] suite