Documentation / git-apply.txton commit t6300: add more body-parsing tests (7140c22)
   1git-apply(1)
   2============
   3
   4NAME
   5----
   6git-apply - Apply a patch to files and/or to the index
   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          [-p<n>] [-C<n>] [--inaccurate-eof] [--recount] [--cached]
  16          [--ignore-space-change | --ignore-whitespace ]
  17          [--whitespace=(nowarn|warn|fix|error|error-all)]
  18          [--exclude=<path>] [--include=<path>] [--directory=<root>]
  19          [--verbose] [<patch>...]
  20
  21DESCRIPTION
  22-----------
  23Reads the supplied diff output (i.e. "a patch") and applies it to files.
  24With the `--index` option the patch is also applied to the index, and
  25with the `--cached` option the patch is only applied to the index.
  26Without these options, the command applies the patch only to files,
  27and does not require them to be in a git repository.
  28
  29This command applies the patch but does not create a commit.  Use
  30linkgit:git-am[1] to create commits from patches generated by
  31linkgit:git-format-patch[1] and/or received by email.
  32
  33OPTIONS
  34-------
  35<patch>...::
  36        The files to read the patch from.  '-' can be used to read
  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::
  44        Similar to `--stat`, but shows the number of added and
  45        deleted lines in decimal notation and the pathname without
  46        abbreviation, to make it more machine friendly.  For
  47        binary files, outputs two `-` instead of saying
  48        `0 0`.  Turns off "apply".
  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
  58        applicable to the current working tree and/or the index
  59        file and detects errors.  Turns off "apply".
  60
  61--index::
  62        When `--check` is in effect, or when applying the patch
  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
  66        the file to be patched in the working tree is not
  67        up-to-date, it is flagged as an error.  This flag also
  68        causes the index file to be updated.
  69
  70--cached::
  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
  73        without using the working tree. This implies `--index`.
  74
  75--build-fake-ancestor=<file>::
  76        Newer 'git diff' output has embedded 'index information'
  77        for each blob to help identify the original version that
  78        the patch applies to.  When this flag is given, and if
  79        the original versions of the blobs are available locally,
  80        builds a temporary index containing those blobs.
  81+
  82When a pure mode change is encountered (which has no index information),
  83the information is read from the current index instead.
  84
  85-R::
  86--reverse::
  87        Apply the patch in reverse.
  88
  89--reject::
  90        For atomicity, 'git apply' by default fails the whole patch and
  91        does not touch the working tree when some of the hunks
  92        do not apply.  This option makes it apply
  93        the parts of the patch that are applicable, and leave the
  94        rejected hunks in corresponding *.rej files.
  95
  96-z::
  97        When `--numstat` has been given, do not munge pathnames,
  98        but use a NUL-terminated machine-readable format.
  99+
 100Without this option, each pathname output will have TAB, LF, double quotes,
 101and backslash characters replaced with `\t`, `\n`, `\"`, and `\\`,
 102respectively, and the pathname will be enclosed in double quotes if
 103any of those replacements occurred.
 104
 105-p<n>::
 106        Remove <n> leading slashes from traditional diff paths. The
 107        default is 1.
 108
 109-C<n>::
 110        Ensure at least <n> lines of surrounding context match before
 111        and after each change.  When fewer lines of surrounding
 112        context exist they all must match.  By default no context is
 113        ever ignored.
 114
 115--unidiff-zero::
 116        By default, 'git apply' expects that the patch being
 117        applied is a unified diff with at least one line of context.
 118        This provides good safety measures, but breaks down when
 119        applying a diff generated with `--unified=0`. To bypass these
 120        checks use `--unidiff-zero`.
 121+
 122Note, for the reasons stated above usage of context-free patches is
 123discouraged.
 124
 125--apply::
 126        If you use any of the options marked "Turns off
 127        'apply'" above, 'git apply' reads and outputs the
 128        requested information without actually applying the
 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
 134        patch.  This can be used to extract the common part between
 135        two files by first running 'diff' on them and applying
 136        the result with this option, which would apply the
 137        deletion part but not the addition part.
 138
 139--allow-binary-replacement::
 140--binary::
 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.
 145
 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
 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+
 156When `--exclude` and `--include` patterns are used, they are examined in the
 157order they appear on the command line, and the first match determines if a
 158patch to each path is used.  A patch to a path that does not match any
 159include/exclude pattern is used by default if there is no include pattern
 160on the command line, and ignored if there is any include pattern.
 161
 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
 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+
 179By default, the command outputs warning messages but applies the patch.
 180When `git-apply` is used for statistics and not applying a
 181patch, it defaults to `nowarn`.
 182+
 183You can use different `<action>` values to control this
 184behavior:
 185+
 186* `nowarn` turns off the trailing whitespace warning.
 187* `warn` outputs warnings for a few such errors, but applies the
 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
 191  used to consider only trailing whitespace characters as errors, and the
 192  fix involved 'stripping' them, but modern gits do more).
 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.
 196
 197--inaccurate-eof::
 198        Under certain circumstances, some versions of 'diff' do not correctly
 199        detect a missing new-line at the end of the file. As a result, patches
 200        created by such 'diff' programs do not record incomplete lines
 201        correctly. This option adds support for applying such patches by
 202        working around this bug.
 203
 204-v::
 205--verbose::
 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.
 209
 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
 215--directory=<root>::
 216        Prepend <root> to all filenames.  If a "-p" argument was also passed,
 217        it is applied before prepending the new root.
 218+
 219For example, a patch that talks about updating `a/git-gui.sh` to `b/git-gui.sh`
 220can be applied to the file in the working tree `modules/git-gui/git-gui.sh` by
 221running `git apply --directory=modules/git-gui`.
 222
 223Configuration
 224-------------
 225
 226apply.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.
 230apply.whitespace::
 231        When no `--whitespace` flag is given from the command
 232        line, this configuration item is used as the default.
 233
 234Submodules
 235----------
 236If the patch contains any changes to submodules then 'git apply'
 237treats these changes as follows.
 238
 239If `--index` is specified (explicitly or implicitly), then the submodule
 240commits must match the index exactly for the patch to apply.  If any
 241of the submodules are checked-out, then these check-outs are completely
 242ignored, i.e., they are not required to be up-to-date or clean and they
 243are not updated.
 244
 245If `--index` is not specified, then the submodule commits in the patch
 246are ignored and only the absence or presence of the corresponding
 247subdirectory is checked and (if possible) updated.
 248
 249SEE ALSO
 250--------
 251linkgit:git-am[1].
 252
 253GIT
 254---
 255Part of the linkgit:git[1] suite