1GIT-APPLY(1)                      Git Manual                      GIT-APPLY(1)
2
3
4

NAME

6       git-apply - Apply a patch to files and/or to the index
7

SYNOPSIS

9       git apply [--stat] [--numstat] [--summary] [--check] [--index]
10                 [--apply] [--no-add] [--build-fake-ancestor=<file>] [-R | --reverse]
11                 [--allow-binary-replacement | --binary] [--reject] [-z]
12                 [-pNUM] [-CNUM] [--inaccurate-eof] [--recount] [--cached]
13                 [--ignore-space-change | --ignore-whitespace ]
14                 [--whitespace=<nowarn|warn|fix|error|error-all>]
15                 [--exclude=PATH] [--include=PATH] [--directory=<root>]
16                 [--verbose] [<patch>...]
17
18

DESCRIPTION

20       Reads the supplied diff output (i.e. "a patch") and applies it to
21       files. With the --index option the patch is also applied to the index,
22       and with the --cache option the patch is only applied to the index.
23       Without these options, the command applies the patch only to files, and
24       does not require them to be in a git repository.
25

OPTIONS

27       <patch>...
28           The files to read the patch from.  - can be used to read from the
29           standard input.
30
31       --stat
32           Instead of applying the patch, output diffstat for the input. Turns
33           off "apply".
34
35       --numstat
36           Similar to --stat, but shows the number of added and deleted lines
37           in decimal notation and the pathname without abbreviation, to make
38           it more machine friendly. For binary files, outputs two - instead
39           of saying 0 0. Turns off "apply".
40
41       --summary
42           Instead of applying the patch, output a condensed summary of
43           information obtained from git diff extended headers, such as
44           creations, renames and mode changes. Turns off "apply".
45
46       --check
47           Instead of applying the patch, see if the patch is applicable to
48           the current working tree and/or the index file and detects errors.
49           Turns off "apply".
50
51       --index
52           When --check is in effect, or when applying the patch (which is the
53           default when none of the options that disables it is in effect),
54           make sure the patch is applicable to what the current index file
55           records. If the file to be patched in the working tree is not
56           up-to-date, it is flagged as an error. This flag also causes the
57           index file to be updated.
58
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
64       --build-fake-ancestor=<file>
65           Newer git diff output has embedded index information for each blob
66           to help identify the original version that the patch applies to.
67           When this flag is given, and if the original versions of the blobs
68           are available locally, builds a temporary index containing those
69           blobs.
70
71           When a pure mode change is encountered (which has no index
72           information), the information is read from the current index
73           instead.
74
75       -R, --reverse
76           Apply the patch in reverse.
77
78       --reject
79           For atomicity, git apply by default fails the whole patch and does
80           not touch the working tree when some of the hunks do not apply.
81           This option makes it apply the parts of the patch that are
82           applicable, and leave the rejected hunks in corresponding *.rej
83           files.
84
85       -z
86           When --numstat has been given, do not munge pathnames, but use a
87           NUL-terminated machine-readable format.
88
89           Without this option, each pathname output will have TAB, LF, double
90           quotes, and backslash characters replaced with \t, \n, \", and \\,
91           respectively, and the pathname will be enclosed in double quotes if
92           any of those replacements occurred.
93
94       -p<n>
95           Remove <n> leading slashes from traditional diff paths. The default
96           is 1.
97
98       -C<n>
99           Ensure at least <n> lines of surrounding context match before and
100           after each change. When fewer lines of surrounding context exist
101           they all must match. By default no context is ever ignored.
102
103       --unidiff-zero
104           By default, git apply expects that the patch being applied is a
105           unified diff with at least one line of context. This provides good
106           safety measures, but breaks down when applying a diff generated
107           with --unified=0. To bypass these checks use --unidiff-zero.
108
109           Note, for the reasons stated above usage of context-free patches is
110           discouraged.
111
112       --apply
113           If you use any of the options marked "Turns off apply" above, git
114           apply reads and outputs the requested information without actually
115           applying the patch. Give this flag after those flags to also apply
116           the patch.
117
118       --no-add
119           When applying a patch, ignore additions made by the patch. This can
120           be used to extract the common part between two files by first
121           running diff on them and applying the result with this option,
122           which would apply the deletion part but not the addition part.
123
124       --allow-binary-replacement, --binary
125           Historically we did not allow binary patch applied without an
126           explicit permission from the user, and this flag was the way to do
127           so. Currently we always allow binary patch application, so this is
128           a no-op.
129
130       --exclude=<path-pattern>
131           Don’t apply changes to files matching the given path pattern. This
132           can be useful when importing patchsets, where you want to exclude
133           certain files or directories.
134
135       --include=<path-pattern>
136           Apply changes to files matching the given path pattern. This can be
137           useful when importing patchsets, where you want to include certain
138           files or directories.
139
140           When --exclude and --include patterns are used, they are examined
141           in the order they appear on the command line, and the first match
142           determines if a patch to each path is used. A patch to a path that
143           does not match any include/exclude pattern is used by default if
144           there is no include pattern on the command line, and ignored if
145           there is any include pattern.
146
147       --ignore-space-change, --ignore-whitespace
148           When applying a patch, ignore changes in whitespace in context
149           lines if necessary. Context lines will preserve their whitespace,
150           and they will not undergo whitespace fixing regardless of the value
151           of the --whitespace option. New lines will still be fixed, though.
152
153       --whitespace=<action>
154           When applying a patch, detect a new or modified line that has
155           whitespace errors. What are considered whitespace errors is
156           controlled by core.whitespace configuration. By default, trailing
157           whitespaces (including lines that solely consist of whitespaces)
158           and a space character that is immediately followed by a tab
159           character inside the initial indent of the line are considered
160           whitespace errors.
161
162           By default, the command outputs warning messages but applies the
163           patch. When git-apply is used for statistics and not applying a
164           patch, it defaults to nowarn.
165
166           You can use different <action> values to control this behavior:
167
168           ·    nowarn turns off the trailing whitespace warning.
169
170           ·    warn outputs warnings for a few such errors, but applies the
171               patch as-is (default).
172
173           ·    fix outputs warnings for a few such errors, and applies the
174               patch after fixing them (strip is a synonym --- the tool used
175               to consider only trailing whitespace characters as errors, and
176               the fix involved stripping them, but modern gits do more).
177
178           ·    error outputs warnings for a few such errors, and refuses to
179               apply the patch.
180
181           ·    error-all is similar to error but shows all errors.
182
183       --inaccurate-eof
184           Under certain circumstances, some versions of diff do not correctly
185           detect a missing new-line at the end of the file. As a result,
186           patches created by such diff programs do not record incomplete
187           lines correctly. This option adds support for applying such patches
188           by working around this bug.
189
190       -v, --verbose
191           Report progress to stderr. By default, only a message about the
192           current patch being applied will be printed. This option will cause
193           additional information to be reported.
194
195       --recount
196           Do not trust the line counts in the hunk headers, but infer them by
197           inspecting the patch (e.g. after editing the patch without
198           adjusting the hunk headers appropriately).
199
200       --directory=<root>
201           Prepend <root> to all filenames. If a "-p" argument was also
202           passed, it is applied before prepending the new root.
203
204           For example, a patch that talks about updating a/git-gui.sh to
205           b/git-gui.sh can be applied to the file in the working tree
206           modules/git-gui/git-gui.sh by running git apply
207           --directory=modules/git-gui.
208

CONFIGURATION

210       apply.ignorewhitespace
211           Set to change if you want changes in whitespace to be ignored by
212           default. Set to one of: no, none, never, false if you want changes
213           in whitespace to be significant.
214
215       apply.whitespace
216           When no --whitespace flag is given from the command line, this
217           configuration item is used as the default.
218

SUBMODULES

220       If the patch contains any changes to submodules then git apply treats
221       these changes as follows.
222
223       If --index is specified (explicitly or implicitly), then the submodule
224       commits must match the index exactly for the patch to apply. If any of
225       the submodules are checked-out, then these check-outs are completely
226       ignored, i.e., they are not required to be up-to-date or clean and they
227       are not updated.
228
229       If --index is not specified, then the submodule commits in the patch
230       are ignored and only the absence or presence of the corresponding
231       subdirectory is checked and (if possible) updated.
232

AUTHOR

234       Written by Linus Torvalds <torvalds@osdl.org[1]>
235

DOCUMENTATION

237       Documentation by Junio C Hamano
238

GIT

240       Part of the git(1) suite
241

NOTES

243        1. torvalds@osdl.org
244           mailto:torvalds@osdl.org
245
246
247
248Git 1.7.1                         08/16/2017                      GIT-APPLY(1)
Impressum