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