]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-apply.txt
documentation: move git(7) to git(1)
[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]
0b9a9dd0 12'git-apply' [--stat] [--numstat] [--summary] [--check] [--index]
7a988699 13 [--apply] [--no-add] [--build-fake-ancestor <file>] [-R | --reverse]
0b9a9dd0
AR
14 [--allow-binary-replacement | --binary] [--reject] [-z]
15 [-pNUM] [-CNUM] [--inaccurate-eof] [--cached]
91af7ae5 16 [--whitespace=<nowarn|warn|fix|error|error-all>]
0b9a9dd0 17 [--exclude=PATH] [--verbose] [<patch>...]
d0587fd5
JH
18
19DESCRIPTION
20-----------
f73ae1fc 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>::
d88156e9
JH
67 Newer git-diff output has embedded 'index information'
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
5684ed6d
JF
76-R, --reverse::
77 Apply the patch in reverse.
78
79--reject::
5162e697 80 For atomicity, linkgit:git-apply[1] by default fails the whole patch and
5684ed6d
JF
81 does not touch the working tree when some of the hunks
82 do not apply. This option makes it apply
b32d37a3 83 the parts of the patch that are applicable, and leave the
8938045a 84 rejected hunks in corresponding *.rej files.
5684ed6d 85
d88156e9
JH
86-z::
87 When showing the index information, do not munge paths,
88 but use NUL terminated machine readable format. Without
89 this flag, the pathnames output will have TAB, LF, and
90 backslash characters replaced with `\t`, `\n`, and `\\`,
91 respectively.
92
e36f8b60
DB
93-p<n>::
94 Remove <n> leading slashes from traditional diff paths. The
95 default is 1.
96
47495887
EB
97-C<n>::
98 Ensure at least <n> lines of surrounding context match before
99 and after each change. When fewer lines of surrounding
74237d62 100 context exist they all must match. By default no context is
47495887
EB
101 ever ignored.
102
f58bb6fb 103--unidiff-zero::
5162e697 104 By default, linkgit:git-apply[1] expects that the patch being
f58bb6fb
JF
105 applied is a unified diff with at least one line of context.
106 This provides good safety measures, but breaks down when
107 applying a diff generated with --unified=0. To bypass these
108 checks use '--unidiff-zero'.
109+
110Note, for the reasons stated above usage of context-free patches are
111discouraged.
112
12dd6e8c 113--apply::
5684ed6d 114 If you use any of the options marked "Turns off
5162e697 115 'apply'" above, linkgit:git-apply[1] reads and outputs the
12dd6e8c
JH
116 information you asked without actually applying the
117 patch. Give this flag after those flags to also apply
118 the patch.
119
e433705d
JH
120--no-add::
121 When applying a patch, ignore additions made by the
71a9883d 122 patch. This can be used to extract the common part between
e433705d
JH
123 two files by first running `diff` on them and applying
124 the result with this option, which would apply the
125 deletion part but not addition part.
d0587fd5 126
5684ed6d 127--allow-binary-replacement, --binary::
2b6eef94
JH
128 Historically we did not allow binary patch applied
129 without an explicit permission from the user, and this
130 flag was the way to do so. Currently we always allow binary
131 patch application, so this is a no-op.
27dedf0c 132
5684ed6d
JF
133--exclude=<path-pattern>::
134 Don't apply changes to files matching the given path pattern. This can
135 be useful when importing patchsets, where you want to exclude certain
136 files or directories.
137
91af7ae5
JH
138--whitespace=<action>::
139 When applying a patch, detect a new or modified line that has
140 whitespace errors. What are considered whitespace errors is
141 controlled by `core.whitespace` configuration. By default,
142 trailing whitespaces (including lines that solely consist of
143 whitespaces) and a space character that is immediately followed
144 by a tab character inside the initial indent of the line are
145 considered whitespace errors.
146+
147By default, the command outputs warning messages but applies the patch.
5162e697 148When linkgit:git-apply[1] is used for statistics and not applying a
91af7ae5
JH
149patch, it defaults to `nowarn`.
150+
151You can use different `<action>` to control this
152behavior:
8273c79a
JH
153+
154* `nowarn` turns off the trailing whitespace warning.
155* `warn` outputs warnings for a few such errors, but applies the
91af7ae5
JH
156 patch as-is (default).
157* `fix` outputs warnings for a few such errors, and applies the
158 patch after fixing them (`strip` is a synonym --- the tool
159 used to consider only trailing whitespaces as errors, and the
160 fix involved 'stripping' them, but modern gits do more).
8273c79a
JH
161* `error` outputs warnings for a few such errors, and refuses
162 to apply the patch.
163* `error-all` is similar to `error` but shows all errors.
8273c79a 164
f847c07b 165--inaccurate-eof::
5684ed6d
JF
166 Under certain circumstances, some versions of diff do not correctly
167 detect a missing new-line at the end of the file. As a result, patches
168 created by such diff programs do not record incomplete lines
169 correctly. This option adds support for applying such patches by
170 working around this bug.
171
0b9a9dd0 172-v, --verbose::
5684ed6d
JF
173 Report progress to stderr. By default, only a message about the
174 current patch being applied will be printed. This option will cause
175 additional information to be reported.
8273c79a
JH
176
177Configuration
178-------------
179
180apply.whitespace::
181 When no `--whitespace` flag is given from the command
182 line, this configuration item is used as the default.
183
e06c5a6c
SV
184Submodules
185----------
5162e697 186If the patch contains any changes to submodules then linkgit:git-apply[1]
e06c5a6c
SV
187treats these changes as follows.
188
189If --index is specified (explicitly or implicitly), then the submodule
190commits must match the index exactly for the patch to apply. If any
191of the submodules are checked-out, then these check-outs are completely
192ignored, i.e., they are not required to be up-to-date or clean and they
193are not updated.
194
195If --index is not specified, then the submodule commits in the patch
196are ignored and only the absence of presence of the corresponding
197subdirectory is checked and (if possible) updated.
8273c79a 198
d0587fd5
JH
199Author
200------
201Written by Linus Torvalds <torvalds@osdl.org>
202
203Documentation
204--------------
205Documentation by Junio C Hamano
206
207GIT
208---
9e1f0a85 209Part of the linkgit:git[1] suite