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