blame: honor the diff heuristic options and config
[git/git.git] / Documentation / diff-options.txt
1 // Please don't remove this comment as asciidoc behaves badly when
2 // the first non-empty line is ifdef/ifndef. The symptom is that
3 // without this comment the <git-diff-core> attribute conditionally
4 // defined below ends up being defined unconditionally.
5 // Last checked with asciidoc 7.0.2.
6
7 ifndef::git-format-patch[]
8 ifndef::git-diff[]
9 ifndef::git-log[]
10 :git-diff-core: 1
11 endif::git-log[]
12 endif::git-diff[]
13 endif::git-format-patch[]
14
15 ifdef::git-format-patch[]
16 -p::
17 --no-stat::
18 Generate plain patches without any diffstats.
19 endif::git-format-patch[]
20
21 ifndef::git-format-patch[]
22 -p::
23 -u::
24 --patch::
25 Generate patch (see section on generating patches).
26 ifdef::git-diff[]
27 This is the default.
28 endif::git-diff[]
29
30 -s::
31 --no-patch::
32 Suppress diff output. Useful for commands like `git show` that
33 show the patch by default, or to cancel the effect of `--patch`.
34 endif::git-format-patch[]
35
36 -U<n>::
37 --unified=<n>::
38 Generate diffs with <n> lines of context instead of
39 the usual three.
40 ifndef::git-format-patch[]
41 Implies `-p`.
42 endif::git-format-patch[]
43
44 ifndef::git-format-patch[]
45 --raw::
46 ifndef::git-log[]
47 Generate the diff in raw format.
48 ifdef::git-diff-core[]
49 This is the default.
50 endif::git-diff-core[]
51 endif::git-log[]
52 ifdef::git-log[]
53 For each commit, show a summary of changes using the raw diff
54 format. See the "RAW OUTPUT FORMAT" section of
55 linkgit:git-diff[1]. This is different from showing the log
56 itself in raw format, which you can achieve with
57 `--format=raw`.
58 endif::git-log[]
59 endif::git-format-patch[]
60
61 ifndef::git-format-patch[]
62 --patch-with-raw::
63 Synonym for `-p --raw`.
64 endif::git-format-patch[]
65
66 include::diff-heuristic-options.txt[]
67
68 --minimal::
69 Spend extra time to make sure the smallest possible
70 diff is produced.
71
72 --patience::
73 Generate a diff using the "patience diff" algorithm.
74
75 --histogram::
76 Generate a diff using the "histogram diff" algorithm.
77
78 --diff-algorithm={patience|minimal|histogram|myers}::
79 Choose a diff algorithm. The variants are as follows:
80 +
81 --
82 `default`, `myers`;;
83 The basic greedy diff algorithm. Currently, this is the default.
84 `minimal`;;
85 Spend extra time to make sure the smallest possible diff is
86 produced.
87 `patience`;;
88 Use "patience diff" algorithm when generating patches.
89 `histogram`;;
90 This algorithm extends the patience algorithm to "support
91 low-occurrence common elements".
92 --
93 +
94 For instance, if you configured diff.algorithm variable to a
95 non-default value and want to use the default one, then you
96 have to use `--diff-algorithm=default` option.
97
98 --stat[=<width>[,<name-width>[,<count>]]]::
99 Generate a diffstat. By default, as much space as necessary
100 will be used for the filename part, and the rest for the graph
101 part. Maximum width defaults to terminal width, or 80 columns
102 if not connected to a terminal, and can be overridden by
103 `<width>`. The width of the filename part can be limited by
104 giving another width `<name-width>` after a comma. The width
105 of the graph part can be limited by using
106 `--stat-graph-width=<width>` (affects all commands generating
107 a stat graph) or by setting `diff.statGraphWidth=<width>`
108 (does not affect `git format-patch`).
109 By giving a third parameter `<count>`, you can limit the
110 output to the first `<count>` lines, followed by `...` if
111 there are more.
112 +
113 These parameters can also be set individually with `--stat-width=<width>`,
114 `--stat-name-width=<name-width>` and `--stat-count=<count>`.
115
116 --numstat::
117 Similar to `--stat`, but shows number of added and
118 deleted lines in decimal notation and pathname without
119 abbreviation, to make it more machine friendly. For
120 binary files, outputs two `-` instead of saying
121 `0 0`.
122
123 --shortstat::
124 Output only the last line of the `--stat` format containing total
125 number of modified files, as well as number of added and deleted
126 lines.
127
128 --dirstat[=<param1,param2,...>]::
129 Output the distribution of relative amount of changes for each
130 sub-directory. The behavior of `--dirstat` can be customized by
131 passing it a comma separated list of parameters.
132 The defaults are controlled by the `diff.dirstat` configuration
133 variable (see linkgit:git-config[1]).
134 The following parameters are available:
135 +
136 --
137 `changes`;;
138 Compute the dirstat numbers by counting the lines that have been
139 removed from the source, or added to the destination. This ignores
140 the amount of pure code movements within a file. In other words,
141 rearranging lines in a file is not counted as much as other changes.
142 This is the default behavior when no parameter is given.
143 `lines`;;
144 Compute the dirstat numbers by doing the regular line-based diff
145 analysis, and summing the removed/added line counts. (For binary
146 files, count 64-byte chunks instead, since binary files have no
147 natural concept of lines). This is a more expensive `--dirstat`
148 behavior than the `changes` behavior, but it does count rearranged
149 lines within a file as much as other changes. The resulting output
150 is consistent with what you get from the other `--*stat` options.
151 `files`;;
152 Compute the dirstat numbers by counting the number of files changed.
153 Each changed file counts equally in the dirstat analysis. This is
154 the computationally cheapest `--dirstat` behavior, since it does
155 not have to look at the file contents at all.
156 `cumulative`;;
157 Count changes in a child directory for the parent directory as well.
158 Note that when using `cumulative`, the sum of the percentages
159 reported may exceed 100%. The default (non-cumulative) behavior can
160 be specified with the `noncumulative` parameter.
161 <limit>;;
162 An integer parameter specifies a cut-off percent (3% by default).
163 Directories contributing less than this percentage of the changes
164 are not shown in the output.
165 --
166 +
167 Example: The following will count changed files, while ignoring
168 directories with less than 10% of the total amount of changed files,
169 and accumulating child directory counts in the parent directories:
170 `--dirstat=files,10,cumulative`.
171
172 --summary::
173 Output a condensed summary of extended header information
174 such as creations, renames and mode changes.
175
176 ifndef::git-format-patch[]
177 --patch-with-stat::
178 Synonym for `-p --stat`.
179 endif::git-format-patch[]
180
181 ifndef::git-format-patch[]
182
183 -z::
184 ifdef::git-log[]
185 Separate the commits with NULs instead of with new newlines.
186 +
187 Also, when `--raw` or `--numstat` has been given, do not munge
188 pathnames and use NULs as output field terminators.
189 endif::git-log[]
190 ifndef::git-log[]
191 When `--raw`, `--numstat`, `--name-only` or `--name-status` has been
192 given, do not munge pathnames and use NULs as output field terminators.
193 endif::git-log[]
194 +
195 Without this option, each pathname output will have TAB, LF, double quotes,
196 and backslash characters replaced with `\t`, `\n`, `\"`, and `\\`,
197 respectively, and the pathname will be enclosed in double quotes if
198 any of those replacements occurred.
199
200 --name-only::
201 Show only names of changed files.
202
203 --name-status::
204 Show only names and status of changed files. See the description
205 of the `--diff-filter` option on what the status letters mean.
206
207 --submodule[=<format>]::
208 Specify how differences in submodules are shown. When `--submodule`
209 or `--submodule=log` is given, the 'log' format is used. This format lists
210 the commits in the range like linkgit:git-submodule[1] `summary` does.
211 Omitting the `--submodule` option or specifying `--submodule=short`,
212 uses the 'short' format. This format just shows the names of the commits
213 at the beginning and end of the range. Can be tweaked via the
214 `diff.submodule` configuration variable.
215
216 --color[=<when>]::
217 Show colored diff.
218 `--color` (i.e. without '=<when>') is the same as `--color=always`.
219 '<when>' can be one of `always`, `never`, or `auto`.
220 ifdef::git-diff[]
221 It can be changed by the `color.ui` and `color.diff`
222 configuration settings.
223 endif::git-diff[]
224
225 --no-color::
226 Turn off colored diff.
227 ifdef::git-diff[]
228 This can be used to override configuration settings.
229 endif::git-diff[]
230 It is the same as `--color=never`.
231
232 --word-diff[=<mode>]::
233 Show a word diff, using the <mode> to delimit changed words.
234 By default, words are delimited by whitespace; see
235 `--word-diff-regex` below. The <mode> defaults to 'plain', and
236 must be one of:
237 +
238 --
239 color::
240 Highlight changed words using only colors. Implies `--color`.
241 plain::
242 Show words as `[-removed-]` and `{+added+}`. Makes no
243 attempts to escape the delimiters if they appear in the input,
244 so the output may be ambiguous.
245 porcelain::
246 Use a special line-based format intended for script
247 consumption. Added/removed/unchanged runs are printed in the
248 usual unified diff format, starting with a `+`/`-`/` `
249 character at the beginning of the line and extending to the
250 end of the line. Newlines in the input are represented by a
251 tilde `~` on a line of its own.
252 none::
253 Disable word diff again.
254 --
255 +
256 Note that despite the name of the first mode, color is used to
257 highlight the changed parts in all modes if enabled.
258
259 --word-diff-regex=<regex>::
260 Use <regex> to decide what a word is, instead of considering
261 runs of non-whitespace to be a word. Also implies
262 `--word-diff` unless it was already enabled.
263 +
264 Every non-overlapping match of the
265 <regex> is considered a word. Anything between these matches is
266 considered whitespace and ignored(!) for the purposes of finding
267 differences. You may want to append `|[^[:space:]]` to your regular
268 expression to make sure that it matches all non-whitespace characters.
269 A match that contains a newline is silently truncated(!) at the
270 newline.
271 +
272 For example, `--word-diff-regex=.` will treat each character as a word
273 and, correspondingly, show differences character by character.
274 +
275 The regex can also be set via a diff driver or configuration option, see
276 linkgit:gitattributes[5] or linkgit:git-config[1]. Giving it explicitly
277 overrides any diff driver or configuration setting. Diff drivers
278 override configuration settings.
279
280 --color-words[=<regex>]::
281 Equivalent to `--word-diff=color` plus (if a regex was
282 specified) `--word-diff-regex=<regex>`.
283 endif::git-format-patch[]
284
285 --no-renames::
286 Turn off rename detection, even when the configuration
287 file gives the default to do so.
288
289 ifndef::git-format-patch[]
290 --check::
291 Warn if changes introduce conflict markers or whitespace errors.
292 What are considered whitespace errors is controlled by `core.whitespace`
293 configuration. By default, trailing whitespaces (including
294 lines that solely consist of whitespaces) and a space character
295 that is immediately followed by a tab character inside the
296 initial indent of the line are considered whitespace errors.
297 Exits with non-zero status if problems are found. Not compatible
298 with --exit-code.
299
300 --ws-error-highlight=<kind>::
301 Highlight whitespace errors on lines specified by <kind>
302 in the color specified by `color.diff.whitespace`. <kind>
303 is a comma separated list of `old`, `new`, `context`. When
304 this option is not given, only whitespace errors in `new`
305 lines are highlighted. E.g. `--ws-error-highlight=new,old`
306 highlights whitespace errors on both deleted and added lines.
307 `all` can be used as a short-hand for `old,new,context`.
308
309 endif::git-format-patch[]
310
311 --full-index::
312 Instead of the first handful of characters, show the full
313 pre- and post-image blob object names on the "index"
314 line when generating patch format output.
315
316 --binary::
317 In addition to `--full-index`, output a binary diff that
318 can be applied with `git-apply`.
319
320 --abbrev[=<n>]::
321 Instead of showing the full 40-byte hexadecimal object
322 name in diff-raw format output and diff-tree header
323 lines, show only a partial prefix. This is
324 independent of the `--full-index` option above, which controls
325 the diff-patch output format. Non default number of
326 digits can be specified with `--abbrev=<n>`.
327
328 -B[<n>][/<m>]::
329 --break-rewrites[=[<n>][/<m>]]::
330 Break complete rewrite changes into pairs of delete and
331 create. This serves two purposes:
332 +
333 It affects the way a change that amounts to a total rewrite of a file
334 not as a series of deletion and insertion mixed together with a very
335 few lines that happen to match textually as the context, but as a
336 single deletion of everything old followed by a single insertion of
337 everything new, and the number `m` controls this aspect of the -B
338 option (defaults to 60%). `-B/70%` specifies that less than 30% of the
339 original should remain in the result for Git to consider it a total
340 rewrite (i.e. otherwise the resulting patch will be a series of
341 deletion and insertion mixed together with context lines).
342 +
343 When used with -M, a totally-rewritten file is also considered as the
344 source of a rename (usually -M only considers a file that disappeared
345 as the source of a rename), and the number `n` controls this aspect of
346 the -B option (defaults to 50%). `-B20%` specifies that a change with
347 addition and deletion compared to 20% or more of the file's size are
348 eligible for being picked up as a possible source of a rename to
349 another file.
350
351 -M[<n>]::
352 --find-renames[=<n>]::
353 ifndef::git-log[]
354 Detect renames.
355 endif::git-log[]
356 ifdef::git-log[]
357 If generating diffs, detect and report renames for each commit.
358 For following files across renames while traversing history, see
359 `--follow`.
360 endif::git-log[]
361 If `n` is specified, it is a threshold on the similarity
362 index (i.e. amount of addition/deletions compared to the
363 file's size). For example, `-M90%` means Git should consider a
364 delete/add pair to be a rename if more than 90% of the file
365 hasn't changed. Without a `%` sign, the number is to be read as
366 a fraction, with a decimal point before it. I.e., `-M5` becomes
367 0.5, and is thus the same as `-M50%`. Similarly, `-M05` is
368 the same as `-M5%`. To limit detection to exact renames, use
369 `-M100%`. The default similarity index is 50%.
370
371 -C[<n>]::
372 --find-copies[=<n>]::
373 Detect copies as well as renames. See also `--find-copies-harder`.
374 If `n` is specified, it has the same meaning as for `-M<n>`.
375
376 --find-copies-harder::
377 For performance reasons, by default, `-C` option finds copies only
378 if the original file of the copy was modified in the same
379 changeset. This flag makes the command
380 inspect unmodified files as candidates for the source of
381 copy. This is a very expensive operation for large
382 projects, so use it with caution. Giving more than one
383 `-C` option has the same effect.
384
385 -D::
386 --irreversible-delete::
387 Omit the preimage for deletes, i.e. print only the header but not
388 the diff between the preimage and `/dev/null`. The resulting patch
389 is not meant to be applied with `patch` or `git apply`; this is
390 solely for people who want to just concentrate on reviewing the
391 text after the change. In addition, the output obviously lack
392 enough information to apply such a patch in reverse, even manually,
393 hence the name of the option.
394 +
395 When used together with `-B`, omit also the preimage in the deletion part
396 of a delete/create pair.
397
398 -l<num>::
399 The `-M` and `-C` options require O(n^2) processing time where n
400 is the number of potential rename/copy targets. This
401 option prevents rename/copy detection from running if
402 the number of rename/copy targets exceeds the specified
403 number.
404
405 ifndef::git-format-patch[]
406 --diff-filter=[(A|C|D|M|R|T|U|X|B)...[*]]::
407 Select only files that are Added (`A`), Copied (`C`),
408 Deleted (`D`), Modified (`M`), Renamed (`R`), have their
409 type (i.e. regular file, symlink, submodule, ...) changed (`T`),
410 are Unmerged (`U`), are
411 Unknown (`X`), or have had their pairing Broken (`B`).
412 Any combination of the filter characters (including none) can be used.
413 When `*` (All-or-none) is added to the combination, all
414 paths are selected if there is any file that matches
415 other criteria in the comparison; if there is no file
416 that matches other criteria, nothing is selected.
417
418 -S<string>::
419 Look for differences that change the number of occurrences of
420 the specified string (i.e. addition/deletion) in a file.
421 Intended for the scripter's use.
422 +
423 It is useful when you're looking for an exact block of code (like a
424 struct), and want to know the history of that block since it first
425 came into being: use the feature iteratively to feed the interesting
426 block in the preimage back into `-S`, and keep going until you get the
427 very first version of the block.
428
429 -G<regex>::
430 Look for differences whose patch text contains added/removed
431 lines that match <regex>.
432 +
433 To illustrate the difference between `-S<regex> --pickaxe-regex` and
434 `-G<regex>`, consider a commit with the following diff in the same
435 file:
436 +
437 ----
438 + return !regexec(regexp, two->ptr, 1, &regmatch, 0);
439 ...
440 - hit = !regexec(regexp, mf2.ptr, 1, &regmatch, 0);
441 ----
442 +
443 While `git log -G"regexec\(regexp"` will show this commit, `git log
444 -S"regexec\(regexp" --pickaxe-regex` will not (because the number of
445 occurrences of that string did not change).
446 +
447 See the 'pickaxe' entry in linkgit:gitdiffcore[7] for more
448 information.
449
450 --pickaxe-all::
451 When `-S` or `-G` finds a change, show all the changes in that
452 changeset, not just the files that contain the change
453 in <string>.
454
455 --pickaxe-regex::
456 Treat the <string> given to `-S` as an extended POSIX regular
457 expression to match.
458 endif::git-format-patch[]
459
460 -O<orderfile>::
461 Output the patch in the order specified in the
462 <orderfile>, which has one shell glob pattern per line.
463 This overrides the `diff.orderFile` configuration variable
464 (see linkgit:git-config[1]). To cancel `diff.orderFile`,
465 use `-O/dev/null`.
466
467 ifndef::git-format-patch[]
468 -R::
469 Swap two inputs; that is, show differences from index or
470 on-disk file to tree contents.
471
472 --relative[=<path>]::
473 When run from a subdirectory of the project, it can be
474 told to exclude changes outside the directory and show
475 pathnames relative to it with this option. When you are
476 not in a subdirectory (e.g. in a bare repository), you
477 can name which subdirectory to make the output relative
478 to by giving a <path> as an argument.
479 endif::git-format-patch[]
480
481 -a::
482 --text::
483 Treat all files as text.
484
485 --ignore-space-at-eol::
486 Ignore changes in whitespace at EOL.
487
488 -b::
489 --ignore-space-change::
490 Ignore changes in amount of whitespace. This ignores whitespace
491 at line end, and considers all other sequences of one or
492 more whitespace characters to be equivalent.
493
494 -w::
495 --ignore-all-space::
496 Ignore whitespace when comparing lines. This ignores
497 differences even if one line has whitespace where the other
498 line has none.
499
500 --ignore-blank-lines::
501 Ignore changes whose lines are all blank.
502
503 --inter-hunk-context=<lines>::
504 Show the context between diff hunks, up to the specified number
505 of lines, thereby fusing hunks that are close to each other.
506
507 -W::
508 --function-context::
509 Show whole surrounding functions of changes.
510
511 ifndef::git-format-patch[]
512 ifndef::git-log[]
513 --exit-code::
514 Make the program exit with codes similar to diff(1).
515 That is, it exits with 1 if there were differences and
516 0 means no differences.
517
518 --quiet::
519 Disable all output of the program. Implies `--exit-code`.
520 endif::git-log[]
521 endif::git-format-patch[]
522
523 --ext-diff::
524 Allow an external diff helper to be executed. If you set an
525 external diff driver with linkgit:gitattributes[5], you need
526 to use this option with linkgit:git-log[1] and friends.
527
528 --no-ext-diff::
529 Disallow external diff drivers.
530
531 --textconv::
532 --no-textconv::
533 Allow (or disallow) external text conversion filters to be run
534 when comparing binary files. See linkgit:gitattributes[5] for
535 details. Because textconv filters are typically a one-way
536 conversion, the resulting diff is suitable for human
537 consumption, but cannot be applied. For this reason, textconv
538 filters are enabled by default only for linkgit:git-diff[1] and
539 linkgit:git-log[1], but not for linkgit:git-format-patch[1] or
540 diff plumbing commands.
541
542 --ignore-submodules[=<when>]::
543 Ignore changes to submodules in the diff generation. <when> can be
544 either "none", "untracked", "dirty" or "all", which is the default.
545 Using "none" will consider the submodule modified when it either contains
546 untracked or modified files or its HEAD differs from the commit recorded
547 in the superproject and can be used to override any settings of the
548 'ignore' option in linkgit:git-config[1] or linkgit:gitmodules[5]. When
549 "untracked" is used submodules are not considered dirty when they only
550 contain untracked content (but they are still scanned for modified
551 content). Using "dirty" ignores all changes to the work tree of submodules,
552 only changes to the commits stored in the superproject are shown (this was
553 the behavior until 1.7.0). Using "all" hides all changes to submodules.
554
555 --src-prefix=<prefix>::
556 Show the given source prefix instead of "a/".
557
558 --dst-prefix=<prefix>::
559 Show the given destination prefix instead of "b/".
560
561 --no-prefix::
562 Do not show any source or destination prefix.
563
564 For more detailed explanation on these common options, see also
565 linkgit:gitdiffcore[7].