6 git-apply - Apply patch on a git index file and a work tree
12 'git-apply' [--stat] [--numstat] [--summary] [--check] [--index] [--apply]
13 [--no-add] [--index-info] [--allow-binary-replacement | --binary]
14 [-R | --reverse] [--reject] [-z] [-pNUM] [-CNUM] [--inaccurate-eof]
15 [--whitespace=<nowarn|warn|error|error-all|strip>] [--exclude=PATH]
16 [--cached] [--verbose] [<patch>...]
20 Reads supplied diff output and applies it on a git index file
26 The files to read patch from. '-' can be used to read
27 from the standard input.
30 Instead of applying the patch, output diffstat for the
31 input. Turns off "apply".
34 Similar to \--stat, but shows number of added and
35 deleted lines in decimal notation and pathname without
36 abbreviation, to make it more machine friendly. Turns
40 Instead of applying the patch, output a condensed
41 summary of information obtained from git diff extended
42 headers, such as creations, renames and mode changes.
46 Instead of applying the patch, see if the patch is
47 applicable to the current work tree and/or the index
48 file and detects errors. Turns off "apply".
51 When --check is in effect, or when applying the patch
52 (which is the default when none of the options that
53 disables it is in effect), make sure the patch is
54 applicable to what the current index file records. If
55 the file to be patched in the work tree is not
56 up-to-date, it is flagged as an error. This flag also
57 causes the index file to be updated.
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'.
65 Newer git-diff output has embedded 'index information'
66 for each blob to help identify the original version that
67 the patch applies to. When this flag is given, and if
68 the original version of the blob is available locally,
69 outputs information about them to the standard output.
72 Apply the patch in reverse.
75 For atomicity, gitlink:git-apply[1] by default fails the whole patch and
76 does not touch the working tree when some of the hunks
77 do not apply. This option makes it apply
78 the parts of the patch that are applicable, and leave the
79 rejected hunks in corresponding *.rej files.
82 When showing the index information, do not munge paths,
83 but use NUL terminated machine readable format. Without
84 this flag, the pathnames output will have TAB, LF, and
85 backslash characters replaced with `\t`, `\n`, and `\\`,
89 Remove <n> leading slashes from traditional diff paths. The
93 Ensure at least <n> lines of surrounding context match before
94 and after each change. When fewer lines of surrounding
95 context exist they all must match. By default no context is
99 If you use any of the options marked "Turns off
100 'apply'" above, gitlink:git-apply[1] reads and outputs the
101 information you asked without actually applying the
102 patch. Give this flag after those flags to also apply
106 When applying a patch, ignore additions made by the
107 patch. This can be used to extract common part between
108 two files by first running `diff` on them and applying
109 the result with this option, which would apply the
110 deletion part but not addition part.
112 --allow-binary-replacement, --binary::
113 When applying a patch, which is a git-enhanced patch
114 that was prepared to record the pre- and post-image object
115 name in full, and the path being patched exactly matches
116 the object the patch applies to (i.e. "index" line's
117 pre-image object name is what is in the working tree),
118 and the post-image object is available in the object
119 database, use the post-image object as the patch
120 result. This allows binary files to be patched in a
123 --exclude=<path-pattern>::
124 Don't apply changes to files matching the given path pattern. This can
125 be useful when importing patchsets, where you want to exclude certain
126 files or directories.
128 --whitespace=<option>::
129 When applying a patch, detect a new or modified line
130 that ends with trailing whitespaces (this includes a
131 line that solely consists of whitespaces). By default,
132 the command outputs warning messages and applies the
134 When gitlink:git-apply[1] is used for statistics and not applying a
135 patch, it defaults to `nowarn`.
136 You can use different `<option>` to control this
139 * `nowarn` turns off the trailing whitespace warning.
140 * `warn` outputs warnings for a few such errors, but applies the
142 * `error` outputs warnings for a few such errors, and refuses
144 * `error-all` is similar to `error` but shows all errors.
145 * `strip` outputs warnings for a few such errors, strips out the
146 trailing whitespaces and applies the patch.
149 Under certain circumstances, some versions of diff do not correctly
150 detect a missing new-line at the end of the file. As a result, patches
151 created by such diff programs do not record incomplete lines
152 correctly. This option adds support for applying such patches by
153 working around this bug.
156 Report progress to stderr. By default, only a message about the
157 current patch being applied will be printed. This option will cause
158 additional information to be reported.
164 When no `--whitespace` flag is given from the command
165 line, this configuration item is used as the default.
170 Written by Linus Torvalds <torvalds@osdl.org>
174 Documentation by Junio C Hamano
178 Part of the gitlink:git[7] suite