2005-06-22 11:30:17 +02:00
|
|
|
git-apply(1)
|
|
|
|
============
|
|
|
|
|
|
|
|
NAME
|
|
|
|
----
|
2009-11-22 20:43:42 +01:00
|
|
|
git-apply - Apply a patch to files and/or to the index
|
2005-06-22 11:30:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
--------
|
2005-12-31 18:37:15 +01:00
|
|
|
[verse]
|
2018-05-26 14:08:46 +02:00
|
|
|
'git apply' [--stat] [--numstat] [--summary] [--check] [--index | --intent-to-add] [--3way]
|
2008-12-28 00:03:57 +01:00
|
|
|
[--apply] [--no-add] [--build-fake-ancestor=<file>] [-R | --reverse]
|
2007-04-16 08:20:40 +02:00
|
|
|
[--allow-binary-replacement | --binary] [--reject] [-z]
|
2010-10-08 19:31:15 +02:00
|
|
|
[-p<n>] [-C<n>] [--inaccurate-eof] [--recount] [--cached]
|
2016-03-24 12:56:16 +01:00
|
|
|
[--ignore-space-change | --ignore-whitespace]
|
2010-10-08 19:31:17 +02:00
|
|
|
[--whitespace=(nowarn|warn|fix|error|error-all)]
|
2010-10-08 19:31:15 +02:00
|
|
|
[--exclude=<path>] [--include=<path>] [--directory=<root>]
|
2021-12-13 23:03:27 +01:00
|
|
|
[--verbose | --quiet] [--unsafe-paths] [--allow-empty] [<patch>...]
|
2005-06-22 11:30:17 +02:00
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
-----------
|
2009-11-22 20:43:42 +01:00
|
|
|
Reads the supplied diff output (i.e. "a patch") and applies it to files.
|
2016-03-24 12:56:17 +01:00
|
|
|
When running from a subdirectory in a repository, patched paths
|
|
|
|
outside the directory are ignored.
|
2009-11-22 20:43:42 +01:00
|
|
|
With the `--index` option the patch is also applied to the index, and
|
2011-03-03 10:28:30 +01:00
|
|
|
with the `--cached` option the patch is only applied to the index.
|
2009-11-22 20:43:42 +01:00
|
|
|
Without these options, the command applies the patch only to files,
|
2013-01-21 20:17:53 +01:00
|
|
|
and does not require them to be in a Git repository.
|
2005-06-22 11:30:17 +02:00
|
|
|
|
2010-08-03 20:41:50 +02:00
|
|
|
This command applies the patch but does not create a commit. Use
|
|
|
|
linkgit:git-am[1] to create commits from patches generated by
|
|
|
|
linkgit:git-format-patch[1] and/or received by email.
|
|
|
|
|
2005-06-22 11:30:17 +02:00
|
|
|
OPTIONS
|
|
|
|
-------
|
2005-07-14 05:28:55 +02:00
|
|
|
<patch>...::
|
2009-03-02 07:42:44 +01:00
|
|
|
The files to read the patch from. '-' can be used to read
|
2005-07-14 05:28:55 +02:00
|
|
|
from the standard input.
|
2005-06-22 11:30:17 +02:00
|
|
|
|
|
|
|
--stat::
|
|
|
|
Instead of applying the patch, output diffstat for the
|
2005-07-14 05:28:55 +02:00
|
|
|
input. Turns off "apply".
|
2005-06-22 11:30:17 +02:00
|
|
|
|
2005-10-28 11:43:31 +02:00
|
|
|
--numstat::
|
2009-11-22 20:43:53 +01:00
|
|
|
Similar to `--stat`, but shows the number of added and
|
2009-03-02 07:42:44 +01:00
|
|
|
deleted lines in decimal notation and the pathname without
|
2006-12-26 09:15:26 +01:00
|
|
|
abbreviation, to make it more machine friendly. For
|
|
|
|
binary files, outputs two `-` instead of saying
|
|
|
|
`0 0`. Turns off "apply".
|
2005-10-28 11:43:31 +02:00
|
|
|
|
2005-06-22 11:30:17 +02:00
|
|
|
--summary::
|
|
|
|
Instead of applying the patch, output a condensed
|
|
|
|
summary of information obtained from git diff extended
|
|
|
|
headers, such as creations, renames and mode changes.
|
2005-07-14 05:28:55 +02:00
|
|
|
Turns off "apply".
|
2005-06-22 11:30:17 +02:00
|
|
|
|
|
|
|
--check::
|
|
|
|
Instead of applying the patch, see if the patch is
|
2009-11-22 20:53:29 +01:00
|
|
|
applicable to the current working tree and/or the index
|
2005-07-14 05:28:55 +02:00
|
|
|
file and detects errors. Turns off "apply".
|
2005-06-22 11:30:17 +02:00
|
|
|
|
|
|
|
--index::
|
2020-08-21 01:10:51 +02:00
|
|
|
Apply the patch to both the index and the working tree (or
|
|
|
|
merely check that it would apply cleanly to both if `--check` is
|
|
|
|
in effect). Note that `--index` expects index entries and
|
|
|
|
working tree copies for relevant paths to be identical (their
|
|
|
|
contents and metadata such as file mode must match), and will
|
|
|
|
raise an error if they are not, even if the patch would apply
|
|
|
|
cleanly to both the index and the working tree in isolation.
|
2005-06-22 11:30:17 +02:00
|
|
|
|
2006-08-25 02:56:55 +02:00
|
|
|
--cached::
|
2020-08-21 01:10:51 +02:00
|
|
|
Apply the patch to just the index, without touching the working
|
|
|
|
tree. If `--check` is in effect, merely check that it would
|
|
|
|
apply cleanly to the index entry.
|
2006-08-25 02:56:55 +02:00
|
|
|
|
2018-05-26 14:08:46 +02:00
|
|
|
--intent-to-add::
|
|
|
|
When applying the patch only to the working tree, mark new
|
|
|
|
files to be added to the index later (see `--intent-to-add`
|
|
|
|
option in linkgit:git-add[1]). This option is ignored unless
|
|
|
|
running in a Git repository and `--index` is not specified.
|
|
|
|
Note that `--index` could be implied by other options such
|
|
|
|
as `--cached` or `--3way`.
|
|
|
|
|
2012-05-10 23:08:29 +02:00
|
|
|
-3::
|
|
|
|
--3way::
|
2021-04-07 01:25:32 +02:00
|
|
|
Attempt 3-way merge if the patch records the identity of blobs it is supposed
|
|
|
|
to apply to and we have those blobs available locally, possibly leaving the
|
2012-05-10 23:08:29 +02:00
|
|
|
conflict markers in the files in the working tree for the user to
|
2021-04-08 04:13:44 +02:00
|
|
|
resolve. This option implies the `--index` option unless the
|
|
|
|
`--cached` option is used, and is incompatible with the `--reject` option.
|
|
|
|
When used with the `--cached` option, any conflicts are left at higher stages
|
|
|
|
in the cache.
|
2012-05-10 23:08:29 +02:00
|
|
|
|
2008-12-28 00:03:57 +01:00
|
|
|
--build-fake-ancestor=<file>::
|
2010-01-10 00:33:00 +01:00
|
|
|
Newer 'git diff' output has embedded 'index information'
|
2005-10-15 06:56:46 +02:00
|
|
|
for each blob to help identify the original version that
|
|
|
|
the patch applies to. When this flag is given, and if
|
2009-03-02 07:42:44 +01:00
|
|
|
the original versions of the blobs are available locally,
|
2007-09-18 00:34:06 +02:00
|
|
|
builds a temporary index containing those blobs.
|
|
|
|
+
|
|
|
|
When a pure mode change is encountered (which has no index information),
|
|
|
|
the information is read from the current index instead.
|
2005-10-15 06:56:46 +02:00
|
|
|
|
2008-06-08 03:36:09 +02:00
|
|
|
-R::
|
|
|
|
--reverse::
|
2006-08-25 02:56:55 +02:00
|
|
|
Apply the patch in reverse.
|
|
|
|
|
|
|
|
--reject::
|
2010-01-10 00:33:00 +01:00
|
|
|
For atomicity, 'git apply' by default fails the whole patch and
|
2006-08-25 02:56:55 +02:00
|
|
|
does not touch the working tree when some of the hunks
|
|
|
|
do not apply. This option makes it apply
|
2006-08-28 02:51:05 +02:00
|
|
|
the parts of the patch that are applicable, and leave the
|
2006-08-28 00:53:20 +02:00
|
|
|
rejected hunks in corresponding *.rej files.
|
2006-08-25 02:56:55 +02:00
|
|
|
|
2005-10-15 06:56:46 +02:00
|
|
|
-z::
|
2009-11-22 20:43:20 +01:00
|
|
|
When `--numstat` has been given, do not munge pathnames,
|
|
|
|
but use a NUL-terminated machine-readable format.
|
|
|
|
+
|
2017-03-02 20:03:52 +01:00
|
|
|
Without this option, pathnames with "unusual" characters are quoted as
|
|
|
|
explained for the configuration variable `core.quotePath` (see
|
|
|
|
linkgit:git-config[1]).
|
2005-10-15 06:56:46 +02:00
|
|
|
|
2006-01-31 06:36:24 +01:00
|
|
|
-p<n>::
|
2018-05-10 16:29:24 +02:00
|
|
|
Remove <n> leading path components (separated by slashes) from
|
|
|
|
traditional diff paths. E.g., with `-p2`, a patch against
|
|
|
|
`a/dir/file` will be applied directly to `file`. The default is
|
|
|
|
1.
|
2006-01-31 06:36:24 +01:00
|
|
|
|
2006-04-10 11:33:06 +02:00
|
|
|
-C<n>::
|
|
|
|
Ensure at least <n> lines of surrounding context match before
|
|
|
|
and after each change. When fewer lines of surrounding
|
2006-06-07 20:32:33 +02:00
|
|
|
context exist they all must match. By default no context is
|
2006-04-10 11:33:06 +02:00
|
|
|
ever ignored.
|
|
|
|
|
2006-09-17 12:55:38 +02:00
|
|
|
--unidiff-zero::
|
2010-01-10 00:33:00 +01:00
|
|
|
By default, 'git apply' expects that the patch being
|
2006-09-17 12:55:38 +02:00
|
|
|
applied is a unified diff with at least one line of context.
|
|
|
|
This provides good safety measures, but breaks down when
|
2009-11-22 20:43:53 +01:00
|
|
|
applying a diff generated with `--unified=0`. To bypass these
|
|
|
|
checks use `--unidiff-zero`.
|
2006-09-17 12:55:38 +02:00
|
|
|
+
|
2009-03-02 07:42:44 +01:00
|
|
|
Note, for the reasons stated above usage of context-free patches is
|
2006-09-17 12:55:38 +02:00
|
|
|
discouraged.
|
|
|
|
|
2005-07-14 05:28:55 +02:00
|
|
|
--apply::
|
2006-08-25 02:56:55 +02:00
|
|
|
If you use any of the options marked "Turns off
|
2010-01-10 00:33:00 +01:00
|
|
|
'apply'" above, 'git apply' reads and outputs the
|
2009-03-02 07:42:44 +01:00
|
|
|
requested information without actually applying the
|
2005-07-14 05:28:55 +02:00
|
|
|
patch. Give this flag after those flags to also apply
|
|
|
|
the patch.
|
|
|
|
|
2005-11-10 05:53:54 +01:00
|
|
|
--no-add::
|
|
|
|
When applying a patch, ignore additions made by the
|
2007-12-12 09:14:20 +01:00
|
|
|
patch. This can be used to extract the common part between
|
2008-07-03 07:55:07 +02:00
|
|
|
two files by first running 'diff' on them and applying
|
2005-11-10 05:53:54 +01:00
|
|
|
the result with this option, which would apply the
|
2009-03-02 07:42:44 +01:00
|
|
|
deletion part but not the addition part.
|
2005-06-22 11:30:17 +02:00
|
|
|
|
2008-06-08 03:36:09 +02:00
|
|
|
--allow-binary-replacement::
|
|
|
|
--binary::
|
2006-09-07 07:45:21 +02:00
|
|
|
Historically we did not allow binary patch applied
|
|
|
|
without an explicit permission from the user, and this
|
|
|
|
flag was the way to do so. Currently we always allow binary
|
|
|
|
patch application, so this is a no-op.
|
2005-11-17 06:32:44 +01:00
|
|
|
|
2006-08-25 02:56:55 +02:00
|
|
|
--exclude=<path-pattern>::
|
|
|
|
Don't apply changes to files matching the given path pattern. This can
|
|
|
|
be useful when importing patchsets, where you want to exclude certain
|
|
|
|
files or directories.
|
|
|
|
|
2008-08-25 10:05:31 +02:00
|
|
|
--include=<path-pattern>::
|
|
|
|
Apply changes to files matching the given path pattern. This can
|
|
|
|
be useful when importing patchsets, where you want to include certain
|
|
|
|
files or directories.
|
|
|
|
+
|
2009-11-22 20:43:53 +01:00
|
|
|
When `--exclude` and `--include` patterns are used, they are examined in the
|
2008-08-25 10:05:31 +02:00
|
|
|
order they appear on the command line, and the first match determines if a
|
|
|
|
patch to each path is used. A patch to a path that does not match any
|
|
|
|
include/exclude pattern is used by default if there is no include pattern
|
|
|
|
on the command line, and ignored if there is any include pattern.
|
|
|
|
|
2009-08-04 13:16:49 +02:00
|
|
|
--ignore-space-change::
|
|
|
|
--ignore-whitespace::
|
|
|
|
When applying a patch, ignore changes in whitespace in context
|
|
|
|
lines if necessary.
|
|
|
|
Context lines will preserve their whitespace, and they will not
|
|
|
|
undergo whitespace fixing regardless of the value of the
|
|
|
|
`--whitespace` option. New lines will still be fixed, though.
|
|
|
|
|
2007-11-24 20:57:41 +01:00
|
|
|
--whitespace=<action>::
|
|
|
|
When applying a patch, detect a new or modified line that has
|
|
|
|
whitespace errors. What are considered whitespace errors is
|
|
|
|
controlled by `core.whitespace` configuration. By default,
|
|
|
|
trailing whitespaces (including lines that solely consist of
|
|
|
|
whitespaces) and a space character that is immediately followed
|
|
|
|
by a tab character inside the initial indent of the line are
|
|
|
|
considered whitespace errors.
|
|
|
|
+
|
|
|
|
By default, the command outputs warning messages but applies the patch.
|
2009-02-28 21:03:54 +01:00
|
|
|
When `git-apply` is used for statistics and not applying a
|
2007-11-24 20:57:41 +01:00
|
|
|
patch, it defaults to `nowarn`.
|
|
|
|
+
|
2009-03-02 07:42:44 +01:00
|
|
|
You can use different `<action>` values to control this
|
2007-11-24 20:57:41 +01:00
|
|
|
behavior:
|
2006-03-02 09:45:48 +01:00
|
|
|
+
|
|
|
|
* `nowarn` turns off the trailing whitespace warning.
|
|
|
|
* `warn` outputs warnings for a few such errors, but applies the
|
2007-11-24 20:57:41 +01:00
|
|
|
patch as-is (default).
|
|
|
|
* `fix` outputs warnings for a few such errors, and applies the
|
|
|
|
patch after fixing them (`strip` is a synonym --- the tool
|
2009-03-02 07:42:44 +01:00
|
|
|
used to consider only trailing whitespace characters as errors, and the
|
2013-01-21 20:17:53 +01:00
|
|
|
fix involved 'stripping' them, but modern Gits do more).
|
2006-03-02 09:45:48 +01:00
|
|
|
* `error` outputs warnings for a few such errors, and refuses
|
|
|
|
to apply the patch.
|
|
|
|
* `error-all` is similar to `error` but shows all errors.
|
|
|
|
|
2006-11-18 06:05:11 +01:00
|
|
|
--inaccurate-eof::
|
2008-07-03 07:37:18 +02:00
|
|
|
Under certain circumstances, some versions of 'diff' do not correctly
|
2006-08-25 02:56:55 +02:00
|
|
|
detect a missing new-line at the end of the file. As a result, patches
|
2008-07-03 07:37:18 +02:00
|
|
|
created by such 'diff' programs do not record incomplete lines
|
2006-08-25 02:56:55 +02:00
|
|
|
correctly. This option adds support for applying such patches by
|
|
|
|
working around this bug.
|
|
|
|
|
2008-06-08 03:36:09 +02:00
|
|
|
-v::
|
|
|
|
--verbose::
|
2006-08-25 02:56:55 +02:00
|
|
|
Report progress to stderr. By default, only a message about the
|
|
|
|
current patch being applied will be printed. This option will cause
|
|
|
|
additional information to be reported.
|
2006-03-02 09:45:48 +01:00
|
|
|
|
2021-12-13 23:03:26 +01:00
|
|
|
-q::
|
|
|
|
--quiet::
|
|
|
|
Suppress stderr output. Messages about patch status and progress
|
|
|
|
will not be printed.
|
|
|
|
|
2008-06-27 19:43:09 +02:00
|
|
|
--recount::
|
|
|
|
Do not trust the line counts in the hunk headers, but infer them
|
|
|
|
by inspecting the patch (e.g. after editing the patch without
|
|
|
|
adjusting the hunk headers appropriately).
|
|
|
|
|
2008-07-07 03:36:01 +02:00
|
|
|
--directory=<root>::
|
2009-03-02 07:42:44 +01:00
|
|
|
Prepend <root> to all filenames. If a "-p" argument was also passed,
|
2008-07-01 01:44:47 +02:00
|
|
|
it is applied before prepending the new root.
|
2008-07-07 03:36:01 +02:00
|
|
|
+
|
|
|
|
For example, a patch that talks about updating `a/git-gui.sh` to `b/git-gui.sh`
|
|
|
|
can be applied to the file in the working tree `modules/git-gui/git-gui.sh` by
|
|
|
|
running `git apply --directory=modules/git-gui`.
|
2008-07-01 01:44:47 +02:00
|
|
|
|
2015-01-30 00:35:24 +01:00
|
|
|
--unsafe-paths::
|
|
|
|
By default, a patch that affects outside the working area
|
|
|
|
(either a Git controlled working tree, or the current working
|
|
|
|
directory when "git apply" is used as a replacement of GNU
|
|
|
|
patch) is rejected as a mistake (or a mischief).
|
|
|
|
+
|
|
|
|
When `git apply` is used as a "better GNU patch", the user can pass
|
|
|
|
the `--unsafe-paths` option to override this safety check. This option
|
|
|
|
has no effect when `--index` or `--cached` is in use.
|
|
|
|
|
2021-12-13 23:03:27 +01:00
|
|
|
--allow-empty::
|
|
|
|
Don't return error for patches containing no diff. This includes
|
|
|
|
empty patches and patches with commit text only.
|
|
|
|
|
2018-04-30 17:35:33 +02:00
|
|
|
CONFIGURATION
|
2006-03-02 09:45:48 +01:00
|
|
|
-------------
|
|
|
|
|
2022-09-07 10:27:00 +02:00
|
|
|
include::includes/cmd-config-section-all.txt[]
|
|
|
|
|
|
|
|
include::config/apply.txt[]
|
2006-03-02 09:45:48 +01:00
|
|
|
|
2018-04-30 17:35:33 +02:00
|
|
|
SUBMODULES
|
2007-08-15 19:22:09 +02:00
|
|
|
----------
|
2010-01-10 00:33:00 +01:00
|
|
|
If the patch contains any changes to submodules then 'git apply'
|
2007-08-15 19:22:09 +02:00
|
|
|
treats these changes as follows.
|
|
|
|
|
2009-11-22 20:43:53 +01:00
|
|
|
If `--index` is specified (explicitly or implicitly), then the submodule
|
2007-08-15 19:22:09 +02:00
|
|
|
commits must match the index exactly for the patch to apply. If any
|
|
|
|
of the submodules are checked-out, then these check-outs are completely
|
2017-08-23 19:49:35 +02:00
|
|
|
ignored, i.e., they are not required to be up to date or clean and they
|
2007-08-15 19:22:09 +02:00
|
|
|
are not updated.
|
|
|
|
|
2009-11-22 20:43:53 +01:00
|
|
|
If `--index` is not specified, then the submodule commits in the patch
|
2009-03-02 07:42:44 +01:00
|
|
|
are ignored and only the absence or presence of the corresponding
|
2007-08-15 19:22:09 +02:00
|
|
|
subdirectory is checked and (if possible) updated.
|
2006-03-02 09:45:48 +01:00
|
|
|
|
2010-08-03 20:41:50 +02:00
|
|
|
SEE ALSO
|
|
|
|
--------
|
|
|
|
linkgit:git-am[1].
|
|
|
|
|
2005-06-22 11:30:17 +02:00
|
|
|
GIT
|
|
|
|
---
|
2008-06-06 09:07:32 +02:00
|
|
|
Part of the linkgit:git[1] suite
|