Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 1 | git-apply(1) |
| 2 | ============ |
| 3 | |
| 4 | NAME |
| 5 | ---- |
Junio C Hamano | 5706e0b | 2009-11-24 10:54:16 | [diff] [blame] | 6 | git-apply - Apply a patch to files and/or to the index |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 7 | |
| 8 | |
| 9 | SYNOPSIS |
| 10 | -------- |
Junio C Hamano | 235a91e | 2006-01-07 01:13:58 | [diff] [blame] | 11 | [verse] |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 12 | 'git apply' [--stat] [--numstat] [--summary] [--check] [--index] |
Junio C Hamano | bd53dbf | 2009-01-18 18:26:37 | [diff] [blame] | 13 | [--apply] [--no-add] [--build-fake-ancestor=<file>] [-R | --reverse] |
Junio C Hamano | 0e3cb53 | 2007-04-17 08:28:11 | [diff] [blame] | 14 | [--allow-binary-replacement | --binary] [--reject] [-z] |
Junio C Hamano | d2179ef | 2010-10-22 04:12:17 | [diff] [blame] | 15 | [-p<n>] [-C<n>] [--inaccurate-eof] [--recount] [--cached] |
Junio C Hamano | fe24db0 | 2009-08-22 05:10:47 | [diff] [blame] | 16 | [--ignore-space-change | --ignore-whitespace ] |
Junio C Hamano | d2179ef | 2010-10-22 04:12:17 | [diff] [blame] | 17 | [--whitespace=(nowarn|warn|fix|error|error-all)] |
| 18 | [--exclude=<path>] [--include=<path>] [--directory=<root>] |
Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 19 | [--verbose] [<patch>...] |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 20 | |
| 21 | DESCRIPTION |
| 22 | ----------- |
Junio C Hamano | 5706e0b | 2009-11-24 10:54:16 | [diff] [blame] | 23 | Reads the supplied diff output (i.e. "a patch") and applies it to files. |
| 24 | With the `--index` option the patch is also applied to the index, and |
Junio C Hamano | 6b8a079 | 2011-03-04 23:54:30 | [diff] [blame^] | 25 | with the `--cached` option the patch is only applied to the index. |
Junio C Hamano | 5706e0b | 2009-11-24 10:54:16 | [diff] [blame] | 26 | Without these options, the command applies the patch only to files, |
| 27 | and does not require them to be in a git repository. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 28 | |
Junio C Hamano | e85e36f | 2010-08-10 05:30:14 | [diff] [blame] | 29 | This command applies the patch but does not create a commit. Use |
| 30 | linkgit:git-am[1] to create commits from patches generated by |
| 31 | linkgit:git-format-patch[1] and/or received by email. |
| 32 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 33 | OPTIONS |
| 34 | ------- |
| 35 | <patch>...:: |
Junio C Hamano | 7924d5e | 2009-03-03 08:28:48 | [diff] [blame] | 36 | The files to read the patch from. '-' can be used to read |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 37 | from the standard input. |
| 38 | |
| 39 | --stat:: |
| 40 | Instead of applying the patch, output diffstat for the |
| 41 | input. Turns off "apply". |
| 42 | |
| 43 | --numstat:: |
Junio C Hamano | 5706e0b | 2009-11-24 10:54:16 | [diff] [blame] | 44 | Similar to `--stat`, but shows the number of added and |
Junio C Hamano | 7924d5e | 2009-03-03 08:28:48 | [diff] [blame] | 45 | deleted lines in decimal notation and the pathname without |
Junio C Hamano | d793de5 | 2006-12-26 09:11:43 | [diff] [blame] | 46 | abbreviation, to make it more machine friendly. For |
| 47 | binary files, outputs two `-` instead of saying |
| 48 | `0 0`. Turns off "apply". |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 49 | |
| 50 | --summary:: |
| 51 | Instead of applying the patch, output a condensed |
| 52 | summary of information obtained from git diff extended |
| 53 | headers, such as creations, renames and mode changes. |
| 54 | Turns off "apply". |
| 55 | |
| 56 | --check:: |
| 57 | Instead of applying the patch, see if the patch is |
Junio C Hamano | 5706e0b | 2009-11-24 10:54:16 | [diff] [blame] | 58 | applicable to the current working tree and/or the index |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 59 | file and detects errors. Turns off "apply". |
| 60 | |
| 61 | --index:: |
Junio C Hamano | 5706e0b | 2009-11-24 10:54:16 | [diff] [blame] | 62 | When `--check` is in effect, or when applying the patch |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 63 | (which is the default when none of the options that |
| 64 | disables it is in effect), make sure the patch is |
| 65 | applicable to what the current index file records. If |
Junio C Hamano | 5706e0b | 2009-11-24 10:54:16 | [diff] [blame] | 66 | the file to be patched in the working tree is not |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 67 | up-to-date, it is flagged as an error. This flag also |
| 68 | causes the index file to be updated. |
| 69 | |
Junio C Hamano | 6b2cee1 | 2006-08-26 08:43:31 | [diff] [blame] | 70 | --cached:: |
Junio C Hamano | 7924d5e | 2009-03-03 08:28:48 | [diff] [blame] | 71 | Apply a patch without touching the working tree. Instead take the |
| 72 | cached data, apply the patch, and store the result in the index |
Junio C Hamano | 5706e0b | 2009-11-24 10:54:16 | [diff] [blame] | 73 | without using the working tree. This implies `--index`. |
Junio C Hamano | 6b2cee1 | 2006-08-26 08:43:31 | [diff] [blame] | 74 | |
Junio C Hamano | bd53dbf | 2009-01-18 18:26:37 | [diff] [blame] | 75 | --build-fake-ancestor=<file>:: |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 76 | Newer 'git diff' output has embedded 'index information' |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 77 | for each blob to help identify the original version that |
| 78 | the patch applies to. When this flag is given, and if |
Junio C Hamano | 7924d5e | 2009-03-03 08:28:48 | [diff] [blame] | 79 | the original versions of the blobs are available locally, |
Junio C Hamano | 01d8f83 | 2007-09-24 07:37:30 | [diff] [blame] | 80 | builds a temporary index containing those blobs. |
| 81 | + |
| 82 | When a pure mode change is encountered (which has no index information), |
| 83 | the information is read from the current index instead. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 84 | |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 85 | -R:: |
| 86 | --reverse:: |
Junio C Hamano | 6b2cee1 | 2006-08-26 08:43:31 | [diff] [blame] | 87 | Apply the patch in reverse. |
| 88 | |
| 89 | --reject:: |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 90 | For atomicity, 'git apply' by default fails the whole patch and |
Junio C Hamano | 6b2cee1 | 2006-08-26 08:43:31 | [diff] [blame] | 91 | does not touch the working tree when some of the hunks |
| 92 | do not apply. This option makes it apply |
Junio C Hamano | 9adfc6a | 2006-08-28 07:18:38 | [diff] [blame] | 93 | the parts of the patch that are applicable, and leave the |
| 94 | rejected hunks in corresponding *.rej files. |
Junio C Hamano | 6b2cee1 | 2006-08-26 08:43:31 | [diff] [blame] | 95 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 96 | -z:: |
Junio C Hamano | 5706e0b | 2009-11-24 10:54:16 | [diff] [blame] | 97 | When `--numstat` has been given, do not munge pathnames, |
| 98 | but use a NUL-terminated machine-readable format. |
| 99 | + |
| 100 | Without this option, each pathname output will have TAB, LF, double quotes, |
| 101 | and backslash characters replaced with `\t`, `\n`, `\"`, and `\\`, |
| 102 | respectively, and the pathname will be enclosed in double quotes if |
| 103 | any of those replacements occurred. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 104 | |
Junio C Hamano | 8af15b0 | 2006-02-01 00:59:26 | [diff] [blame] | 105 | -p<n>:: |
| 106 | Remove <n> leading slashes from traditional diff paths. The |
| 107 | default is 1. |
| 108 | |
Junio C Hamano | 54559c8 | 2006-04-13 07:45:12 | [diff] [blame] | 109 | -C<n>:: |
| 110 | Ensure at least <n> lines of surrounding context match before |
| 111 | and after each change. When fewer lines of surrounding |
Junio C Hamano | 33db437 | 2006-06-07 19:51:45 | [diff] [blame] | 112 | context exist they all must match. By default no context is |
Junio C Hamano | 54559c8 | 2006-04-13 07:45:12 | [diff] [blame] | 113 | ever ignored. |
| 114 | |
Junio C Hamano | 3eb513f | 2006-09-18 02:47:16 | [diff] [blame] | 115 | --unidiff-zero:: |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 116 | By default, 'git apply' expects that the patch being |
Junio C Hamano | 3eb513f | 2006-09-18 02:47:16 | [diff] [blame] | 117 | applied is a unified diff with at least one line of context. |
| 118 | This provides good safety measures, but breaks down when |
Junio C Hamano | 5706e0b | 2009-11-24 10:54:16 | [diff] [blame] | 119 | applying a diff generated with `--unified=0`. To bypass these |
| 120 | checks use `--unidiff-zero`. |
Junio C Hamano | 3eb513f | 2006-09-18 02:47:16 | [diff] [blame] | 121 | + |
Junio C Hamano | 7924d5e | 2009-03-03 08:28:48 | [diff] [blame] | 122 | Note, for the reasons stated above usage of context-free patches is |
Junio C Hamano | 3eb513f | 2006-09-18 02:47:16 | [diff] [blame] | 123 | discouraged. |
| 124 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 125 | --apply:: |
Junio C Hamano | 6b2cee1 | 2006-08-26 08:43:31 | [diff] [blame] | 126 | If you use any of the options marked "Turns off |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 127 | 'apply'" above, 'git apply' reads and outputs the |
Junio C Hamano | 7924d5e | 2009-03-03 08:28:48 | [diff] [blame] | 128 | requested information without actually applying the |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 129 | patch. Give this flag after those flags to also apply |
| 130 | the patch. |
| 131 | |
| 132 | --no-add:: |
| 133 | When applying a patch, ignore additions made by the |
Junio C Hamano | 3a70234 | 2007-12-12 21:34:02 | [diff] [blame] | 134 | patch. This can be used to extract the common part between |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 135 | two files by first running 'diff' on them and applying |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 136 | the result with this option, which would apply the |
Junio C Hamano | 7924d5e | 2009-03-03 08:28:48 | [diff] [blame] | 137 | deletion part but not the addition part. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 138 | |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 139 | --allow-binary-replacement:: |
| 140 | --binary:: |
Junio C Hamano | fd73d89 | 2006-09-14 07:38:22 | [diff] [blame] | 141 | Historically we did not allow binary patch applied |
| 142 | without an explicit permission from the user, and this |
| 143 | flag was the way to do so. Currently we always allow binary |
| 144 | patch application, so this is a no-op. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 145 | |
Junio C Hamano | 6b2cee1 | 2006-08-26 08:43:31 | [diff] [blame] | 146 | --exclude=<path-pattern>:: |
| 147 | Don't apply changes to files matching the given path pattern. This can |
| 148 | be useful when importing patchsets, where you want to exclude certain |
| 149 | files or directories. |
| 150 | |
Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 151 | --include=<path-pattern>:: |
| 152 | Apply changes to files matching the given path pattern. This can |
| 153 | be useful when importing patchsets, where you want to include certain |
| 154 | files or directories. |
| 155 | + |
Junio C Hamano | 5706e0b | 2009-11-24 10:54:16 | [diff] [blame] | 156 | When `--exclude` and `--include` patterns are used, they are examined in the |
Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 157 | order they appear on the command line, and the first match determines if a |
| 158 | patch to each path is used. A patch to a path that does not match any |
| 159 | include/exclude pattern is used by default if there is no include pattern |
| 160 | on the command line, and ignored if there is any include pattern. |
| 161 | |
Junio C Hamano | fe24db0 | 2009-08-22 05:10:47 | [diff] [blame] | 162 | --ignore-space-change:: |
| 163 | --ignore-whitespace:: |
| 164 | When applying a patch, ignore changes in whitespace in context |
| 165 | lines if necessary. |
| 166 | Context lines will preserve their whitespace, and they will not |
| 167 | undergo whitespace fixing regardless of the value of the |
| 168 | `--whitespace` option. New lines will still be fixed, though. |
| 169 | |
Junio C Hamano | 942b35e | 2007-12-09 10:19:33 | [diff] [blame] | 170 | --whitespace=<action>:: |
| 171 | When applying a patch, detect a new or modified line that has |
| 172 | whitespace errors. What are considered whitespace errors is |
| 173 | controlled by `core.whitespace` configuration. By default, |
| 174 | trailing whitespaces (including lines that solely consist of |
| 175 | whitespaces) and a space character that is immediately followed |
| 176 | by a tab character inside the initial indent of the line are |
| 177 | considered whitespace errors. |
| 178 | + |
| 179 | By default, the command outputs warning messages but applies the patch. |
Junio C Hamano | f8a7922 | 2009-03-01 08:02:50 | [diff] [blame] | 180 | When `git-apply` is used for statistics and not applying a |
Junio C Hamano | 942b35e | 2007-12-09 10:19:33 | [diff] [blame] | 181 | patch, it defaults to `nowarn`. |
| 182 | + |
Junio C Hamano | 7924d5e | 2009-03-03 08:28:48 | [diff] [blame] | 183 | You can use different `<action>` values to control this |
Junio C Hamano | 942b35e | 2007-12-09 10:19:33 | [diff] [blame] | 184 | behavior: |
Junio C Hamano | 5f32776 | 2006-03-02 09:14:51 | [diff] [blame] | 185 | + |
| 186 | * `nowarn` turns off the trailing whitespace warning. |
| 187 | * `warn` outputs warnings for a few such errors, but applies the |
Junio C Hamano | 942b35e | 2007-12-09 10:19:33 | [diff] [blame] | 188 | patch as-is (default). |
| 189 | * `fix` outputs warnings for a few such errors, and applies the |
| 190 | patch after fixing them (`strip` is a synonym --- the tool |
Junio C Hamano | 7924d5e | 2009-03-03 08:28:48 | [diff] [blame] | 191 | used to consider only trailing whitespace characters as errors, and the |
Junio C Hamano | 942b35e | 2007-12-09 10:19:33 | [diff] [blame] | 192 | fix involved 'stripping' them, but modern gits do more). |
Junio C Hamano | 5f32776 | 2006-03-02 09:14:51 | [diff] [blame] | 193 | * `error` outputs warnings for a few such errors, and refuses |
| 194 | to apply the patch. |
| 195 | * `error-all` is similar to `error` but shows all errors. |
Junio C Hamano | 5f32776 | 2006-03-02 09:14:51 | [diff] [blame] | 196 | |
Junio C Hamano | 3a97102 | 2006-11-18 22:17:58 | [diff] [blame] | 197 | --inaccurate-eof:: |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 198 | Under certain circumstances, some versions of 'diff' do not correctly |
Junio C Hamano | 6b2cee1 | 2006-08-26 08:43:31 | [diff] [blame] | 199 | detect a missing new-line at the end of the file. As a result, patches |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 200 | created by such 'diff' programs do not record incomplete lines |
Junio C Hamano | 6b2cee1 | 2006-08-26 08:43:31 | [diff] [blame] | 201 | correctly. This option adds support for applying such patches by |
| 202 | working around this bug. |
| 203 | |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 204 | -v:: |
| 205 | --verbose:: |
Junio C Hamano | 6b2cee1 | 2006-08-26 08:43:31 | [diff] [blame] | 206 | Report progress to stderr. By default, only a message about the |
| 207 | current patch being applied will be printed. This option will cause |
| 208 | additional information to be reported. |
Junio C Hamano | 5f32776 | 2006-03-02 09:14:51 | [diff] [blame] | 209 | |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 210 | --recount:: |
| 211 | Do not trust the line counts in the hunk headers, but infer them |
| 212 | by inspecting the patch (e.g. after editing the patch without |
| 213 | adjusting the hunk headers appropriately). |
| 214 | |
Junio C Hamano | 208beb7 | 2008-07-10 02:30:50 | [diff] [blame] | 215 | --directory=<root>:: |
Junio C Hamano | 7924d5e | 2009-03-03 08:28:48 | [diff] [blame] | 216 | Prepend <root> to all filenames. If a "-p" argument was also passed, |
Junio C Hamano | 208beb7 | 2008-07-10 02:30:50 | [diff] [blame] | 217 | it is applied before prepending the new root. |
| 218 | + |
| 219 | For example, a patch that talks about updating `a/git-gui.sh` to `b/git-gui.sh` |
| 220 | can be applied to the file in the working tree `modules/git-gui/git-gui.sh` by |
| 221 | running `git apply --directory=modules/git-gui`. |
| 222 | |
Junio C Hamano | 5f32776 | 2006-03-02 09:14:51 | [diff] [blame] | 223 | Configuration |
| 224 | ------------- |
| 225 | |
Junio C Hamano | fe24db0 | 2009-08-22 05:10:47 | [diff] [blame] | 226 | apply.ignorewhitespace:: |
| 227 | Set to 'change' if you want changes in whitespace to be ignored by default. |
| 228 | Set to one of: no, none, never, false if you want changes in |
| 229 | whitespace to be significant. |
Junio C Hamano | 5f32776 | 2006-03-02 09:14:51 | [diff] [blame] | 230 | apply.whitespace:: |
| 231 | When no `--whitespace` flag is given from the command |
| 232 | line, this configuration item is used as the default. |
| 233 | |
Junio C Hamano | 3b178be | 2007-08-16 04:59:27 | [diff] [blame] | 234 | Submodules |
| 235 | ---------- |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 236 | If the patch contains any changes to submodules then 'git apply' |
Junio C Hamano | 3b178be | 2007-08-16 04:59:27 | [diff] [blame] | 237 | treats these changes as follows. |
| 238 | |
Junio C Hamano | 5706e0b | 2009-11-24 10:54:16 | [diff] [blame] | 239 | If `--index` is specified (explicitly or implicitly), then the submodule |
Junio C Hamano | 3b178be | 2007-08-16 04:59:27 | [diff] [blame] | 240 | commits must match the index exactly for the patch to apply. If any |
| 241 | of the submodules are checked-out, then these check-outs are completely |
| 242 | ignored, i.e., they are not required to be up-to-date or clean and they |
| 243 | are not updated. |
| 244 | |
Junio C Hamano | 5706e0b | 2009-11-24 10:54:16 | [diff] [blame] | 245 | If `--index` is not specified, then the submodule commits in the patch |
Junio C Hamano | 7924d5e | 2009-03-03 08:28:48 | [diff] [blame] | 246 | are ignored and only the absence or presence of the corresponding |
Junio C Hamano | 3b178be | 2007-08-16 04:59:27 | [diff] [blame] | 247 | subdirectory is checked and (if possible) updated. |
Junio C Hamano | 5f32776 | 2006-03-02 09:14:51 | [diff] [blame] | 248 | |
Junio C Hamano | e85e36f | 2010-08-10 05:30:14 | [diff] [blame] | 249 | |
| 250 | SEE ALSO |
| 251 | -------- |
| 252 | linkgit:git-am[1]. |
| 253 | |
| 254 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 255 | Author |
| 256 | ------ |
| 257 | Written by Linus Torvalds <torvalds@osdl.org> |
| 258 | |
| 259 | Documentation |
| 260 | -------------- |
| 261 | Documentation by Junio C Hamano |
| 262 | |
| 263 | GIT |
| 264 | --- |
Junio C Hamano | f7c042d | 2008-06-06 22:50:53 | [diff] [blame] | 265 | Part of the linkgit:git[1] suite |