Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 1 | git-apply(1) |
| 2 | ============ |
| 3 | |
| 4 | NAME |
| 5 | ---- |
Junio C Hamano | 7c73c66 | 2007-01-19 00:37:50 | [diff] [blame] | 6 | git-apply - Apply a patch on a git index file and a working tree |
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 | 01d8f83 | 2007-09-24 07:37:30 | [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 | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame^] | 15 | [-pNUM] [-CNUM] [--inaccurate-eof] [--recount] [--cached] |
Junio C Hamano | 942b35e | 2007-12-09 10:19:33 | [diff] [blame] | 16 | [--whitespace=<nowarn|warn|fix|error|error-all>] |
Junio C Hamano | 0e3cb53 | 2007-04-17 08:28:11 | [diff] [blame] | 17 | [--exclude=PATH] [--verbose] [<patch>...] |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 18 | |
| 19 | DESCRIPTION |
| 20 | ----------- |
| 21 | Reads supplied diff output and applies it on a git index file |
| 22 | and a work tree. |
| 23 | |
| 24 | OPTIONS |
| 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 |
Junio C Hamano | d793de5 | 2006-12-26 09:11:43 | [diff] [blame] | 37 | abbreviation, to make it more machine friendly. For |
| 38 | binary files, outputs two `-` instead of saying |
| 39 | `0 0`. Turns off "apply". |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 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 | |
Junio C Hamano | 6b2cee1 | 2006-08-26 08:43:31 | [diff] [blame] | 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 | |
Junio C Hamano | 01d8f83 | 2007-09-24 07:37:30 | [diff] [blame] | 66 | --build-fake-ancestor <file>:: |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame^] | 67 | Newer `git-diff` output has embedded 'index information' |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 68 | for each blob to help identify the original version that |
| 69 | the patch applies to. When this flag is given, and if |
Junio C Hamano | 01d8f83 | 2007-09-24 07:37:30 | [diff] [blame] | 70 | the original versions of the blobs is available locally, |
| 71 | builds a temporary index containing those blobs. |
| 72 | + |
| 73 | When a pure mode change is encountered (which has no index information), |
| 74 | the information is read from the current index instead. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 75 | |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 76 | -R:: |
| 77 | --reverse:: |
Junio C Hamano | 6b2cee1 | 2006-08-26 08:43:31 | [diff] [blame] | 78 | Apply the patch in reverse. |
| 79 | |
| 80 | --reject:: |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame^] | 81 | For atomicity, `git-apply` by default fails the whole patch and |
Junio C Hamano | 6b2cee1 | 2006-08-26 08:43:31 | [diff] [blame] | 82 | does not touch the working tree when some of the hunks |
| 83 | do not apply. This option makes it apply |
Junio C Hamano | 9adfc6a | 2006-08-28 07:18:38 | [diff] [blame] | 84 | the parts of the patch that are applicable, and leave the |
| 85 | rejected hunks in corresponding *.rej files. |
Junio C Hamano | 6b2cee1 | 2006-08-26 08:43:31 | [diff] [blame] | 86 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 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 | |
Junio C Hamano | 8af15b0 | 2006-02-01 00:59:26 | [diff] [blame] | 94 | -p<n>:: |
| 95 | Remove <n> leading slashes from traditional diff paths. The |
| 96 | default is 1. |
| 97 | |
Junio C Hamano | 54559c8 | 2006-04-13 07:45:12 | [diff] [blame] | 98 | -C<n>:: |
| 99 | Ensure at least <n> lines of surrounding context match before |
| 100 | and after each change. When fewer lines of surrounding |
Junio C Hamano | 33db437 | 2006-06-07 19:51:45 | [diff] [blame] | 101 | context exist they all must match. By default no context is |
Junio C Hamano | 54559c8 | 2006-04-13 07:45:12 | [diff] [blame] | 102 | ever ignored. |
| 103 | |
Junio C Hamano | 3eb513f | 2006-09-18 02:47:16 | [diff] [blame] | 104 | --unidiff-zero:: |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame^] | 105 | By default, `git-apply` expects that the patch being |
Junio C Hamano | 3eb513f | 2006-09-18 02:47:16 | [diff] [blame] | 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 | + |
| 111 | Note, for the reasons stated above usage of context-free patches are |
| 112 | discouraged. |
| 113 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 114 | --apply:: |
Junio C Hamano | 6b2cee1 | 2006-08-26 08:43:31 | [diff] [blame] | 115 | If you use any of the options marked "Turns off |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame^] | 116 | 'apply'" above, `git-apply` reads and outputs the |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 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 |
Junio C Hamano | 3a70234 | 2007-12-12 21:34:02 | [diff] [blame] | 123 | patch. This can be used to extract the common part between |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 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 | |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 128 | --allow-binary-replacement:: |
| 129 | --binary:: |
Junio C Hamano | fd73d89 | 2006-09-14 07:38:22 | [diff] [blame] | 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. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 134 | |
Junio C Hamano | 6b2cee1 | 2006-08-26 08:43:31 | [diff] [blame] | 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 | |
Junio C Hamano | 942b35e | 2007-12-09 10:19:33 | [diff] [blame] | 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 | + |
| 149 | By default, the command outputs warning messages but applies the patch. |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame^] | 150 | When `git-apply is used for statistics and not applying a |
Junio C Hamano | 942b35e | 2007-12-09 10:19:33 | [diff] [blame] | 151 | patch, it defaults to `nowarn`. |
| 152 | + |
| 153 | You can use different `<action>` to control this |
| 154 | behavior: |
Junio C Hamano | 5f32776 | 2006-03-02 09:14:51 | [diff] [blame] | 155 | + |
| 156 | * `nowarn` turns off the trailing whitespace warning. |
| 157 | * `warn` outputs warnings for a few such errors, but applies the |
Junio C Hamano | 942b35e | 2007-12-09 10:19:33 | [diff] [blame] | 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). |
Junio C Hamano | 5f32776 | 2006-03-02 09:14:51 | [diff] [blame] | 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. |
Junio C Hamano | 5f32776 | 2006-03-02 09:14:51 | [diff] [blame] | 166 | |
Junio C Hamano | 3a97102 | 2006-11-18 22:17:58 | [diff] [blame] | 167 | --inaccurate-eof:: |
Junio C Hamano | 6b2cee1 | 2006-08-26 08:43:31 | [diff] [blame] | 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 | |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 174 | -v:: |
| 175 | --verbose:: |
Junio C Hamano | 6b2cee1 | 2006-08-26 08:43:31 | [diff] [blame] | 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. |
Junio C Hamano | 5f32776 | 2006-03-02 09:14:51 | [diff] [blame] | 179 | |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame^] | 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 | |
Junio C Hamano | 5f32776 | 2006-03-02 09:14:51 | [diff] [blame] | 185 | Configuration |
| 186 | ------------- |
| 187 | |
| 188 | apply.whitespace:: |
| 189 | When no `--whitespace` flag is given from the command |
| 190 | line, this configuration item is used as the default. |
| 191 | |
Junio C Hamano | 3b178be | 2007-08-16 04:59:27 | [diff] [blame] | 192 | Submodules |
| 193 | ---------- |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame^] | 194 | If the patch contains any changes to submodules then `git-apply` |
Junio C Hamano | 3b178be | 2007-08-16 04:59:27 | [diff] [blame] | 195 | treats these changes as follows. |
| 196 | |
| 197 | If --index is specified (explicitly or implicitly), then the submodule |
| 198 | commits must match the index exactly for the patch to apply. If any |
| 199 | of the submodules are checked-out, then these check-outs are completely |
| 200 | ignored, i.e., they are not required to be up-to-date or clean and they |
| 201 | are not updated. |
| 202 | |
| 203 | If --index is not specified, then the submodule commits in the patch |
| 204 | are ignored and only the absence of presence of the corresponding |
| 205 | subdirectory is checked and (if possible) updated. |
Junio C Hamano | 5f32776 | 2006-03-02 09:14:51 | [diff] [blame] | 206 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 207 | Author |
| 208 | ------ |
| 209 | Written by Linus Torvalds <torvalds@osdl.org> |
| 210 | |
| 211 | Documentation |
| 212 | -------------- |
| 213 | Documentation by Junio C Hamano |
| 214 | |
| 215 | GIT |
| 216 | --- |
Junio C Hamano | f7c042d | 2008-06-06 22:50:53 | [diff] [blame] | 217 | Part of the linkgit:git[1] suite |