update diff-delta.c copyright
[git/dscho.git] / Documentation / git-apply.txt
blob3bd2c995da7d65977481837486dc15e5e96baf91
1 git-apply(1)
2 ============
4 NAME
5 ----
6 git-apply - Apply a patch on a git index file and a working tree
9 SYNOPSIS
10 --------
11 [verse]
12 'git-apply' [--stat] [--numstat] [--summary] [--check] [--index]
13           [--apply] [--no-add] [--index-info] [-R | --reverse]
14           [--allow-binary-replacement | --binary] [--reject] [-z]
15           [-pNUM] [-CNUM] [--inaccurate-eof] [--cached]
16           [--whitespace=<nowarn|warn|error|error-all|strip>]
17           [--exclude=PATH] [--verbose] [<patch>...]
19 DESCRIPTION
20 -----------
21 Reads supplied diff output and applies it on a git index file
22 and a work tree.
24 OPTIONS
25 -------
26 <patch>...::
27         The files to read patch from.  '-' can be used to read
28         from the standard input.
30 --stat::
31         Instead of applying the patch, output diffstat for the
32         input.  Turns off "apply".
34 --numstat::
35         Similar to \--stat, but shows number of added and
36         deleted lines in decimal notation and pathname without
37         abbreviation, to make it more machine friendly.  For
38         binary files, outputs two `-` instead of saying
39         `0 0`.  Turns off "apply".
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".
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".
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.
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'.
66 --index-info::
67         Newer git-diff output has embedded 'index information'
68         for each blob to help identify the original version that
69         the patch applies to.  When this flag is given, and if
70         the original version of the blob is available locally,
71         outputs information about them to the standard output.
73 -R, --reverse::
74         Apply the patch in reverse.
76 --reject::
77         For atomicity, gitlink:git-apply[1] by default fails the whole patch and
78         does not touch the working tree when some of the hunks
79         do not apply.  This option makes it apply
80         the parts of the patch that are applicable, and leave the
81         rejected hunks in corresponding *.rej files.
83 -z::
84         When showing the index information, do not munge paths,
85         but use NUL terminated machine readable format.  Without
86         this flag, the pathnames output will have TAB, LF, and
87         backslash characters replaced with `\t`, `\n`, and `\\`,
88         respectively.
90 -p<n>::
91         Remove <n> leading slashes from traditional diff paths. The
92         default is 1.
94 -C<n>::
95         Ensure at least <n> lines of surrounding context match before
96         and after each change.  When fewer lines of surrounding
97         context exist they all must match.  By default no context is
98         ever ignored.
100 --unidiff-zero::
101         By default, gitlink:git-apply[1] expects that the patch being
102         applied is a unified diff with at least one line of context.
103         This provides good safety measures, but breaks down when
104         applying a diff generated with --unified=0. To bypass these
105         checks use '--unidiff-zero'.
107 Note, for the reasons stated above usage of context-free patches are
108 discouraged.
110 --apply::
111         If you use any of the options marked "Turns off
112         'apply'" above, gitlink:git-apply[1] reads and outputs the
113         information you asked without actually applying the
114         patch.  Give this flag after those flags to also apply
115         the patch.
117 --no-add::
118         When applying a patch, ignore additions made by the
119         patch.  This can be used to extract common part between
120         two files by first running `diff` on them and applying
121         the result with this option, which would apply the
122         deletion part but not addition part.
124 --allow-binary-replacement, --binary::
125         Historically we did not allow binary patch applied
126         without an explicit permission from the user, and this
127         flag was the way to do so.  Currently we always allow binary
128         patch application, so this is a no-op.
130 --exclude=<path-pattern>::
131         Don't apply changes to files matching the given path pattern. This can
132         be useful when importing patchsets, where you want to exclude certain
133         files or directories.
135 --whitespace=<option>::
136         When applying a patch, detect a new or modified line
137         that ends with trailing whitespaces (this includes a
138         line that solely consists of whitespaces).  By default,
139         the command outputs warning messages and applies the
140         patch.
141         When gitlink:git-apply[1] is used for statistics and not applying a
142         patch, it defaults to `nowarn`.
143         You can use different `<option>` to control this
144         behavior:
146 * `nowarn` turns off the trailing whitespace warning.
147 * `warn` outputs warnings for a few such errors, but applies the
148   patch (default).
149 * `error` outputs warnings for a few such errors, and refuses
150   to apply the patch.
151 * `error-all` is similar to `error` but shows all errors.
152 * `strip` outputs warnings for a few such errors, strips out the
153   trailing whitespaces and applies the patch.
155 --inaccurate-eof::
156         Under certain circumstances, some versions of diff do not correctly
157         detect a missing new-line at the end of the file. As a result, patches
158         created by such diff programs do not record incomplete lines
159         correctly. This option adds support for applying such patches by
160         working around this bug.
162 -v, --verbose::
163         Report progress to stderr. By default, only a message about the
164         current patch being applied will be printed. This option will cause
165         additional information to be reported.
167 Configuration
168 -------------
170 apply.whitespace::
171         When no `--whitespace` flag is given from the command
172         line, this configuration item is used as the default.
175 Author
176 ------
177 Written by Linus Torvalds <torvalds@osdl.org>
179 Documentation
180 --------------
181 Documentation by Junio C Hamano
185 Part of the gitlink:git[7] suite