1git-apply(1) 2============ 3 4NAME 5---- 6git-apply - Apply a patch on a git index file and a working tree 7 8 9SYNOPSIS 10-------- 11[verse] 12'git apply' [--stat] [--numstat] [--summary] [--check] [--index] 13 [--apply] [--no-add] [--build-fake-ancestor <file>] [-R | --reverse] 14 [--allow-binary-replacement | --binary] [--reject] [-z] 15 [-pNUM] [-CNUM] [--inaccurate-eof] [--recount] [--cached] 16 [--whitespace=<nowarn|warn|fix|error|error-all>] 17 [--exclude=PATH] [--directory=<root>] [--verbose] [<patch>...] 18 19DESCRIPTION 20----------- 21Reads supplied 'diff' output and applies it on a git index file 22and a work tree. 23 24OPTIONS 25------- 26<patch>...:: 27 The files to read patch from. '-' can be used to read 28 from the standard input. 29 30--stat:: 31 Instead of applying the patch, output diffstat for the 32 input. Turns off "apply". 33 34--numstat:: 35 Similar to \--stat, but shows number of added and 36 deleted lines in decimal notation and pathname without 37 abbreviation, to make it more machine friendly. For 38 binary files, outputs two `-` instead of saying 39 `0 0`. Turns off "apply". 40 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. 45 Turns off "apply". 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 50 file and detects errors. Turns off "apply". 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 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 66--build-fake-ancestor <file>:: 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 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. 75 76-R:: 77--reverse:: 78 Apply the patch in reverse. 79 80--reject:: 81 For atomicity, 'git-apply' by default fails the whole patch and 82 does not touch the working tree when some of the hunks 83 do not apply. This option makes it apply 84 the parts of the patch that are applicable, and leave the 85 rejected hunks in corresponding *.rej files. 86 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 94-p<n>:: 95 Remove <n> leading slashes from traditional diff paths. The 96 default is 1. 97 98-C<n>:: 99 Ensure at least <n> lines of surrounding context match before 100 and after each change. When fewer lines of surrounding 101 context exist they all must match. By default no context is 102 ever ignored. 103 104--unidiff-zero:: 105 By default, 'git-apply' expects that the patch being 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 114--apply:: 115 If you use any of the options marked "Turns off 116 'apply'" above, 'git-apply' reads and outputs the 117 information you asked without actually applying the 118 patch. Give this flag after those flags to also apply 119 the patch. 120 121--no-add:: 122 When applying a patch, ignore additions made by the 123 patch. This can be used to extract the common part between 124 two files by first running 'diff' on them and applying 125 the result with this option, which would apply the 126 deletion part but not addition part. 127 128--allow-binary-replacement:: 129--binary:: 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. 134 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 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. 150When `git-apply` is used for statistics and not applying a 151patch, it defaults to `nowarn`. 152+ 153You can use different `<action>` to control this 154behavior: 155+ 156* `nowarn` turns off the trailing whitespace warning. 157* `warn` outputs warnings for a few such errors, but applies the 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). 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. 166 167--inaccurate-eof:: 168 Under certain circumstances, some versions of 'diff' do not correctly 169 detect a missing new-line at the end of the file. As a result, patches 170 created by such 'diff' programs do not record incomplete lines 171 correctly. This option adds support for applying such patches by 172 working around this bug. 173 174-v:: 175--verbose:: 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. 179 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 185--directory=<root>:: 186 Prepend <root> to all filenames. If a "-p" argument was passed, too, 187 it is applied before prepending the new root. 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`. 192 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 200Submodules 201---------- 202If the patch contains any changes to submodules then 'git-apply' 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. 214 215Author 216------ 217Written by Linus Torvalds <torvalds@osdl.org> 218 219Documentation 220-------------- 221Documentation by Junio C Hamano 222 223GIT 224--- 225Part of the linkgit:git[1] suite