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