OSDN Git Service

merge original branch.
[tortoisegit/TortoiseGitJp.git] / doc / source / en / TortoiseGit / git_doc / git-diff-index.html.xml
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">\r
3 \r
4 <article lang="en" id="git-diff-index(1)">\r
5 <articleinfo>\r
6     <title>git-diff-index(1)</title>\r
7         <indexterm>\r
8                 <primary>git-diff-index(1)</primary>\r
9         </indexterm>\r
10 </articleinfo>\r
11 <simplesect id="_name">\r
12 <title>NAME</title>\r
13 <simpara>git-diff-index - Compares content and mode of blobs between the index and repository</simpara>\r
14 </simplesect>\r
15 <simplesect id="_synopsis">\r
16 <title>SYNOPSIS</title>\r
17 <simpara><emphasis>git diff-index</emphasis> [-m] [--cached] [&lt;common diff options&gt;] &lt;tree-ish&gt; [&lt;path&gt;&#8230;]</simpara>\r
18 </simplesect>\r
19 <simplesect id="_description">\r
20 <title>DESCRIPTION</title>\r
21 <simpara>Compares the content and mode of the blobs found via a tree\r
22 object with the content of the current index and, optionally\r
23 ignoring the stat state of the file on disk.  When paths are\r
24 specified, compares only those named paths.  Otherwise all\r
25 entries in the index are compared.</simpara>\r
26 </simplesect>\r
27 <simplesect id="_options">\r
28 <title>OPTIONS</title>\r
29 <variablelist>\r
30 <varlistentry>\r
31 <term>\r
32 -p\r
33 </term>\r
34 <term>\r
35 -u\r
36 </term>\r
37 <listitem>\r
38 <simpara>\r
39         Generate patch (see section on generating patches).\r
40         \r
41 </simpara>\r
42 </listitem>\r
43 </varlistentry>\r
44 <varlistentry>\r
45 <term>\r
46 -U&lt;n&gt;\r
47 </term>\r
48 <term>\r
49 --unified=&lt;n&gt;\r
50 </term>\r
51 <listitem>\r
52 <simpara>\r
53         Generate diffs with &lt;n&gt; lines of context instead of\r
54         the usual three. Implies "-p".\r
55 </simpara>\r
56 </listitem>\r
57 </varlistentry>\r
58 <varlistentry>\r
59 <term>\r
60 --raw\r
61 </term>\r
62 <listitem>\r
63 <simpara>\r
64         Generate the raw format.\r
65          This is the default.\r
66 </simpara>\r
67 </listitem>\r
68 </varlistentry>\r
69 <varlistentry>\r
70 <term>\r
71 --patch-with-raw\r
72 </term>\r
73 <listitem>\r
74 <simpara>\r
75         Synonym for "-p --raw".\r
76 </simpara>\r
77 </listitem>\r
78 </varlistentry>\r
79 <varlistentry>\r
80 <term>\r
81 --patience\r
82 </term>\r
83 <listitem>\r
84 <simpara>\r
85         Generate a diff using the "patience diff" algorithm.\r
86 </simpara>\r
87 </listitem>\r
88 </varlistentry>\r
89 <varlistentry>\r
90 <term>\r
91 --stat[=width[,name-width]]\r
92 </term>\r
93 <listitem>\r
94 <simpara>\r
95         Generate a diffstat.  You can override the default\r
96         output width for 80-column terminal by "--stat=width".\r
97         The width of the filename part can be controlled by\r
98         giving another width to it separated by a comma.\r
99 </simpara>\r
100 </listitem>\r
101 </varlistentry>\r
102 <varlistentry>\r
103 <term>\r
104 --numstat\r
105 </term>\r
106 <listitem>\r
107 <simpara>\r
108         Similar to --stat, but shows number of added and\r
109         deleted lines in decimal notation and pathname without\r
110         abbreviation, to make it more machine friendly.  For\r
111         binary files, outputs two <literal>-</literal> instead of saying\r
112         <literal>0 0</literal>.\r
113 </simpara>\r
114 </listitem>\r
115 </varlistentry>\r
116 <varlistentry>\r
117 <term>\r
118 --shortstat\r
119 </term>\r
120 <listitem>\r
121 <simpara>\r
122         Output only the last line of the --stat format containing total\r
123         number of modified files, as well as number of added and deleted\r
124         lines.\r
125 </simpara>\r
126 </listitem>\r
127 </varlistentry>\r
128 <varlistentry>\r
129 <term>\r
130 --dirstat[=limit]\r
131 </term>\r
132 <listitem>\r
133 <simpara>\r
134         Output the distribution of relative amount of changes (number of lines added or\r
135         removed) for each sub-directory. Directories with changes below\r
136         a cut-off percent (3% by default) are not shown. The cut-off percent\r
137         can be set with "--dirstat=limit". Changes in a child directory is not\r
138         counted for the parent directory, unless "--cumulative" is used.\r
139 </simpara>\r
140 </listitem>\r
141 </varlistentry>\r
142 <varlistentry>\r
143 <term>\r
144 --dirstat-by-file[=limit]\r
145 </term>\r
146 <listitem>\r
147 <simpara>\r
148         Same as --dirstat, but counts changed files instead of lines.\r
149 </simpara>\r
150 </listitem>\r
151 </varlistentry>\r
152 <varlistentry>\r
153 <term>\r
154 --summary\r
155 </term>\r
156 <listitem>\r
157 <simpara>\r
158         Output a condensed summary of extended header information\r
159         such as creations, renames and mode changes.\r
160 </simpara>\r
161 </listitem>\r
162 </varlistentry>\r
163 <varlistentry>\r
164 <term>\r
165 --patch-with-stat\r
166 </term>\r
167 <listitem>\r
168 <simpara>\r
169         Synonym for "-p --stat".\r
170         \r
171 </simpara>\r
172 </listitem>\r
173 </varlistentry>\r
174 <varlistentry>\r
175 <term>\r
176 -z\r
177 </term>\r
178 <listitem>\r
179 <simpara>\r
180         NUL-line termination on output.  This affects the --raw\r
181         output field terminator.  Also output from commands such\r
182         as "git-log" will be delimited with NUL between commits.\r
183 </simpara>\r
184 </listitem>\r
185 </varlistentry>\r
186 <varlistentry>\r
187 <term>\r
188 --name-only\r
189 </term>\r
190 <listitem>\r
191 <simpara>\r
192         Show only names of changed files.\r
193 </simpara>\r
194 </listitem>\r
195 </varlistentry>\r
196 <varlistentry>\r
197 <term>\r
198 --name-status\r
199 </term>\r
200 <listitem>\r
201 <simpara>\r
202         Show only names and status of changed files. See the description\r
203         of the <literal>--diff-filter</literal> option on what the status letters mean.\r
204 </simpara>\r
205 </listitem>\r
206 </varlistentry>\r
207 <varlistentry>\r
208 <term>\r
209 --color\r
210 </term>\r
211 <listitem>\r
212 <simpara>\r
213         Show colored diff.\r
214 </simpara>\r
215 </listitem>\r
216 </varlistentry>\r
217 <varlistentry>\r
218 <term>\r
219 --no-color\r
220 </term>\r
221 <listitem>\r
222 <simpara>\r
223         Turn off colored diff, even when the configuration file\r
224         gives the default to color output.\r
225 </simpara>\r
226 </listitem>\r
227 </varlistentry>\r
228 <varlistentry>\r
229 <term>\r
230 --color-words[=&lt;regex&gt;]\r
231 </term>\r
232 <listitem>\r
233 <simpara>\r
234         Show colored word diff, i.e., color words which have changed.\r
235         By default, words are separated by whitespace.\r
236 </simpara>\r
237 <simpara>When a &lt;regex&gt; is specified, every non-overlapping match of the\r
238 &lt;regex&gt; is considered a word.  Anything between these matches is\r
239 considered whitespace and ignored(!) for the purposes of finding\r
240 differences.  You may want to append <literal>|[^[:space:]]</literal> to your regular\r
241 expression to make sure that it matches all non-whitespace characters.\r
242 A match that contains a newline is silently truncated(!) at the\r
243 newline.</simpara>\r
244 <simpara>The regex can also be set via a diff driver or configuration option, see\r
245 <xref linkend="gitattributes(1)"/> or <xref linkend="git-config(1)"/>.  Giving it explicitly\r
246 overrides any diff driver or configuration setting.  Diff drivers\r
247 override configuration settings.</simpara>\r
248 </listitem>\r
249 </varlistentry>\r
250 <varlistentry>\r
251 <term>\r
252 --no-renames\r
253 </term>\r
254 <listitem>\r
255 <simpara>\r
256         Turn off rename detection, even when the configuration\r
257         file gives the default to do so.\r
258 </simpara>\r
259 </listitem>\r
260 </varlistentry>\r
261 <varlistentry>\r
262 <term>\r
263 --check\r
264 </term>\r
265 <listitem>\r
266 <simpara>\r
267         Warn if changes introduce trailing whitespace\r
268         or an indent that uses a space before a tab. Exits with\r
269         non-zero status if problems are found. Not compatible with\r
270         --exit-code.\r
271 </simpara>\r
272 </listitem>\r
273 </varlistentry>\r
274 <varlistentry>\r
275 <term>\r
276 --full-index\r
277 </term>\r
278 <listitem>\r
279 <simpara>\r
280         Instead of the first handful of characters, show the full\r
281         pre- and post-image blob object names on the "index"\r
282         line when generating patch format output.\r
283 </simpara>\r
284 </listitem>\r
285 </varlistentry>\r
286 <varlistentry>\r
287 <term>\r
288 --binary\r
289 </term>\r
290 <listitem>\r
291 <simpara>\r
292         In addition to --full-index, output "binary diff" that\r
293         can be applied with "git apply".\r
294 </simpara>\r
295 </listitem>\r
296 </varlistentry>\r
297 <varlistentry>\r
298 <term>\r
299 --abbrev[=&lt;n&gt;]\r
300 </term>\r
301 <listitem>\r
302 <simpara>\r
303         Instead of showing the full 40-byte hexadecimal object\r
304         name in diff-raw format output and diff-tree header\r
305         lines, show only a partial prefix.  This is\r
306         independent of --full-index option above, which controls\r
307         the diff-patch output format.  Non default number of\r
308         digits can be specified with --abbrev=&lt;n&gt;.\r
309 </simpara>\r
310 </listitem>\r
311 </varlistentry>\r
312 <varlistentry>\r
313 <term>\r
314 -B\r
315 </term>\r
316 <listitem>\r
317 <simpara>\r
318         Break complete rewrite changes into pairs of delete and create.\r
319 </simpara>\r
320 </listitem>\r
321 </varlistentry>\r
322 <varlistentry>\r
323 <term>\r
324 -M\r
325 </term>\r
326 <listitem>\r
327 <simpara>\r
328         Detect renames.\r
329 </simpara>\r
330 </listitem>\r
331 </varlistentry>\r
332 <varlistentry>\r
333 <term>\r
334 -C\r
335 </term>\r
336 <listitem>\r
337 <simpara>\r
338         Detect copies as well as renames.  See also <literal>--find-copies-harder</literal>.\r
339 </simpara>\r
340 </listitem>\r
341 </varlistentry>\r
342 <varlistentry>\r
343 <term>\r
344 --diff-filter=[ACDMRTUXB*]\r
345 </term>\r
346 <listitem>\r
347 <simpara>\r
348         Select only files that are Added (<literal>A</literal>), Copied (<literal>C</literal>),\r
349         Deleted (<literal>D</literal>), Modified (<literal>M</literal>), Renamed (<literal>R</literal>), have their\r
350         type (i.e. regular file, symlink, submodule, &#8230;) changed (<literal>T</literal>),\r
351         are Unmerged (<literal>U</literal>), are\r
352         Unknown (<literal>X</literal>), or have had their pairing Broken (<literal>B</literal>).\r
353         Any combination of the filter characters may be used.\r
354         When <literal>*</literal> (All-or-none) is added to the combination, all\r
355         paths are selected if there is any file that matches\r
356         other criteria in the comparison; if there is no file\r
357         that matches other criteria, nothing is selected.\r
358 </simpara>\r
359 </listitem>\r
360 </varlistentry>\r
361 <varlistentry>\r
362 <term>\r
363 --find-copies-harder\r
364 </term>\r
365 <listitem>\r
366 <simpara>\r
367         For performance reasons, by default, <literal>-C</literal> option finds copies only\r
368         if the original file of the copy was modified in the same\r
369         changeset.  This flag makes the command\r
370         inspect unmodified files as candidates for the source of\r
371         copy.  This is a very expensive operation for large\r
372         projects, so use it with caution.  Giving more than one\r
373         <literal>-C</literal> option has the same effect.\r
374 </simpara>\r
375 </listitem>\r
376 </varlistentry>\r
377 <varlistentry>\r
378 <term>\r
379 -l&lt;num&gt;\r
380 </term>\r
381 <listitem>\r
382 <simpara>\r
383         -M and -C options require O(n^2) processing time where n\r
384         is the number of potential rename/copy targets.  This\r
385         option prevents rename/copy detection from running if\r
386         the number of rename/copy targets exceeds the specified\r
387         number.\r
388 </simpara>\r
389 </listitem>\r
390 </varlistentry>\r
391 <varlistentry>\r
392 <term>\r
393 -S&lt;string&gt;\r
394 </term>\r
395 <listitem>\r
396 <simpara>\r
397         Look for differences that contain the change in &lt;string&gt;.\r
398 </simpara>\r
399 </listitem>\r
400 </varlistentry>\r
401 <varlistentry>\r
402 <term>\r
403 --pickaxe-all\r
404 </term>\r
405 <listitem>\r
406 <simpara>\r
407         When -S finds a change, show all the changes in that\r
408         changeset, not just the files that contain the change\r
409         in &lt;string&gt;.\r
410 </simpara>\r
411 </listitem>\r
412 </varlistentry>\r
413 <varlistentry>\r
414 <term>\r
415 --pickaxe-regex\r
416 </term>\r
417 <listitem>\r
418 <simpara>\r
419         Make the &lt;string&gt; not a plain string but an extended POSIX\r
420         regex to match.\r
421 </simpara>\r
422 </listitem>\r
423 </varlistentry>\r
424 <varlistentry>\r
425 <term>\r
426 -O&lt;orderfile&gt;\r
427 </term>\r
428 <listitem>\r
429 <simpara>\r
430         Output the patch in the order specified in the\r
431         &lt;orderfile&gt;, which has one shell glob pattern per line.\r
432 </simpara>\r
433 </listitem>\r
434 </varlistentry>\r
435 <varlistentry>\r
436 <term>\r
437 -R\r
438 </term>\r
439 <listitem>\r
440 <simpara>\r
441         Swap two inputs; that is, show differences from index or\r
442         on-disk file to tree contents.\r
443 </simpara>\r
444 </listitem>\r
445 </varlistentry>\r
446 <varlistentry>\r
447 <term>\r
448 --relative[=&lt;path&gt;]\r
449 </term>\r
450 <listitem>\r
451 <simpara>\r
452         When run from a subdirectory of the project, it can be\r
453         told to exclude changes outside the directory and show\r
454         pathnames relative to it with this option.  When you are\r
455         not in a subdirectory (e.g. in a bare repository), you\r
456         can name which subdirectory to make the output relative\r
457         to by giving a &lt;path&gt; as an argument.\r
458 </simpara>\r
459 </listitem>\r
460 </varlistentry>\r
461 <varlistentry>\r
462 <term>\r
463 -a\r
464 </term>\r
465 <term>\r
466 --text\r
467 </term>\r
468 <listitem>\r
469 <simpara>\r
470         Treat all files as text.\r
471 </simpara>\r
472 </listitem>\r
473 </varlistentry>\r
474 <varlistentry>\r
475 <term>\r
476 --ignore-space-at-eol\r
477 </term>\r
478 <listitem>\r
479 <simpara>\r
480         Ignore changes in whitespace at EOL.\r
481 </simpara>\r
482 </listitem>\r
483 </varlistentry>\r
484 <varlistentry>\r
485 <term>\r
486 -b\r
487 </term>\r
488 <term>\r
489 --ignore-space-change\r
490 </term>\r
491 <listitem>\r
492 <simpara>\r
493         Ignore changes in amount of whitespace.  This ignores whitespace\r
494         at line end, and considers all other sequences of one or\r
495         more whitespace characters to be equivalent.\r
496 </simpara>\r
497 </listitem>\r
498 </varlistentry>\r
499 <varlistentry>\r
500 <term>\r
501 -w\r
502 </term>\r
503 <term>\r
504 --ignore-all-space\r
505 </term>\r
506 <listitem>\r
507 <simpara>\r
508         Ignore whitespace when comparing lines.  This ignores\r
509         differences even if one line has whitespace where the other\r
510         line has none.\r
511 </simpara>\r
512 </listitem>\r
513 </varlistentry>\r
514 <varlistentry>\r
515 <term>\r
516 --inter-hunk-context=&lt;lines&gt;\r
517 </term>\r
518 <listitem>\r
519 <simpara>\r
520         Show the context between diff hunks, up to the specified number\r
521         of lines, thereby fusing hunks that are close to each other.\r
522 </simpara>\r
523 </listitem>\r
524 </varlistentry>\r
525 <varlistentry>\r
526 <term>\r
527 --exit-code\r
528 </term>\r
529 <listitem>\r
530 <simpara>\r
531         Make the program exit with codes similar to diff(1).\r
532         That is, it exits with 1 if there were differences and\r
533         0 means no differences.\r
534 </simpara>\r
535 </listitem>\r
536 </varlistentry>\r
537 <varlistentry>\r
538 <term>\r
539 --quiet\r
540 </term>\r
541 <listitem>\r
542 <simpara>\r
543         Disable all output of the program. Implies --exit-code.\r
544 </simpara>\r
545 </listitem>\r
546 </varlistentry>\r
547 <varlistentry>\r
548 <term>\r
549 --ext-diff\r
550 </term>\r
551 <listitem>\r
552 <simpara>\r
553         Allow an external diff helper to be executed. If you set an\r
554         external diff driver with <xref linkend="gitattributes(5)"/>, you need\r
555         to use this option with <xref linkend="git-log(1)"/> and friends.\r
556 </simpara>\r
557 </listitem>\r
558 </varlistentry>\r
559 <varlistentry>\r
560 <term>\r
561 --no-ext-diff\r
562 </term>\r
563 <listitem>\r
564 <simpara>\r
565         Disallow external diff drivers.\r
566 </simpara>\r
567 </listitem>\r
568 </varlistentry>\r
569 <varlistentry>\r
570 <term>\r
571 --ignore-submodules\r
572 </term>\r
573 <listitem>\r
574 <simpara>\r
575         Ignore changes to submodules in the diff generation.\r
576 </simpara>\r
577 </listitem>\r
578 </varlistentry>\r
579 <varlistentry>\r
580 <term>\r
581 --src-prefix=&lt;prefix&gt;\r
582 </term>\r
583 <listitem>\r
584 <simpara>\r
585         Show the given source prefix instead of "a/".\r
586 </simpara>\r
587 </listitem>\r
588 </varlistentry>\r
589 <varlistentry>\r
590 <term>\r
591 --dst-prefix=&lt;prefix&gt;\r
592 </term>\r
593 <listitem>\r
594 <simpara>\r
595         Show the given destination prefix instead of "b/".\r
596 </simpara>\r
597 </listitem>\r
598 </varlistentry>\r
599 <varlistentry>\r
600 <term>\r
601 --no-prefix\r
602 </term>\r
603 <listitem>\r
604 <simpara>\r
605         Do not show any source or destination prefix.\r
606 </simpara>\r
607 </listitem>\r
608 </varlistentry>\r
609 </variablelist>\r
610 <simpara>For more detailed explanation on these common options, see also\r
611 <xref linkend="gitdiffcore(7)"/>.</simpara>\r
612 <variablelist>\r
613 <varlistentry>\r
614 <term>\r
615 &lt;tree-ish&gt;\r
616 </term>\r
617 <listitem>\r
618 <simpara>\r
619         The id of a tree object to diff against.\r
620 </simpara>\r
621 </listitem>\r
622 </varlistentry>\r
623 <varlistentry>\r
624 <term>\r
625 --cached\r
626 </term>\r
627 <listitem>\r
628 <simpara>\r
629         do not consider the on-disk file at all\r
630 </simpara>\r
631 </listitem>\r
632 </varlistentry>\r
633 <varlistentry>\r
634 <term>\r
635 -m\r
636 </term>\r
637 <listitem>\r
638 <simpara>\r
639         By default, files recorded in the index but not checked\r
640         out are reported as deleted.  This flag makes\r
641         <emphasis>git-diff-index</emphasis> say that all non-checked-out files are up\r
642         to date.\r
643 </simpara>\r
644 </listitem>\r
645 </varlistentry>\r
646 </variablelist>\r
647 </simplesect>\r
648 <simplesect id="_output_format">\r
649 <title>Output format</title>\r
650 <simpara>The output format from "git-diff-index", "git-diff-tree",\r
651 "git-diff-files" and "git diff --raw" are very similar.</simpara>\r
652 <simpara>These commands all compare two sets of things; what is\r
653 compared differs:</simpara>\r
654 <variablelist>\r
655 <varlistentry>\r
656 <term>\r
657 git-diff-index &lt;tree-ish&gt;\r
658 </term>\r
659 <listitem>\r
660 <simpara>\r
661         compares the &lt;tree-ish&gt; and the files on the filesystem.\r
662 </simpara>\r
663 </listitem>\r
664 </varlistentry>\r
665 <varlistentry>\r
666 <term>\r
667 git-diff-index --cached &lt;tree-ish&gt;\r
668 </term>\r
669 <listitem>\r
670 <simpara>\r
671         compares the &lt;tree-ish&gt; and the index.\r
672 </simpara>\r
673 </listitem>\r
674 </varlistentry>\r
675 <varlistentry>\r
676 <term>\r
677 git-diff-tree [-r] &lt;tree-ish-1&gt; &lt;tree-ish-2&gt; [&lt;pattern&gt;&#8230;]\r
678 </term>\r
679 <listitem>\r
680 <simpara>\r
681         compares the trees named by the two arguments.\r
682 </simpara>\r
683 </listitem>\r
684 </varlistentry>\r
685 <varlistentry>\r
686 <term>\r
687 git-diff-files [&lt;pattern&gt;&#8230;]\r
688 </term>\r
689 <listitem>\r
690 <simpara>\r
691         compares the index and the files on the filesystem.\r
692 </simpara>\r
693 </listitem>\r
694 </varlistentry>\r
695 </variablelist>\r
696 <simpara>An output line is formatted this way:</simpara>\r
697 <literallayout>in-place edit  :100644 100644 bcd1234... 0123456... M file0\r
698 copy-edit      :100644 100644 abcd123... 1234567... C68 file1 file2\r
699 rename-edit    :100644 100644 abcd123... 1234567... R86 file1 file3\r
700 create         :000000 100644 0000000... 1234567... A file4\r
701 delete         :100644 000000 1234567... 0000000... D file5\r
702 unmerged       :000000 000000 0000000... 0000000... U file6</literallayout>\r
703 <simpara>That is, from the left to the right:</simpara>\r
704 <orderedlist numeration="arabic">\r
705 <listitem>\r
706 <simpara>\r
707 a colon.\r
708 </simpara>\r
709 </listitem>\r
710 <listitem>\r
711 <simpara>\r
712 mode for "src"; 000000 if creation or unmerged.\r
713 </simpara>\r
714 </listitem>\r
715 <listitem>\r
716 <simpara>\r
717 a space.\r
718 </simpara>\r
719 </listitem>\r
720 <listitem>\r
721 <simpara>\r
722 mode for "dst"; 000000 if deletion or unmerged.\r
723 </simpara>\r
724 </listitem>\r
725 <listitem>\r
726 <simpara>\r
727 a space.\r
728 </simpara>\r
729 </listitem>\r
730 <listitem>\r
731 <simpara>\r
732 sha1 for "src"; 0{40} if creation or unmerged.\r
733 </simpara>\r
734 </listitem>\r
735 <listitem>\r
736 <simpara>\r
737 a space.\r
738 </simpara>\r
739 </listitem>\r
740 <listitem>\r
741 <simpara>\r
742 sha1 for "dst"; 0{40} if creation, unmerged or "look at work tree".\r
743 </simpara>\r
744 </listitem>\r
745 <listitem>\r
746 <simpara>\r
747 a space.\r
748 </simpara>\r
749 </listitem>\r
750 <listitem>\r
751 <simpara>\r
752 status, followed by optional "score" number.\r
753 </simpara>\r
754 </listitem>\r
755 <listitem>\r
756 <simpara>\r
757 a tab or a NUL when <emphasis>-z</emphasis> option is used.\r
758 </simpara>\r
759 </listitem>\r
760 <listitem>\r
761 <simpara>\r
762 path for "src"\r
763 </simpara>\r
764 </listitem>\r
765 <listitem>\r
766 <simpara>\r
767 a tab or a NUL when <emphasis>-z</emphasis> option is used; only exists for C or R.\r
768 </simpara>\r
769 </listitem>\r
770 <listitem>\r
771 <simpara>\r
772 path for "dst"; only exists for C or R.\r
773 </simpara>\r
774 </listitem>\r
775 <listitem>\r
776 <simpara>\r
777 an LF or a NUL when <emphasis>-z</emphasis> option is used, to terminate the record.\r
778 </simpara>\r
779 </listitem>\r
780 </orderedlist>\r
781 <simpara>Possible status letters are:</simpara>\r
782 <itemizedlist>\r
783 <listitem>\r
784 <simpara>\r
785 A: addition of a file\r
786 </simpara>\r
787 </listitem>\r
788 <listitem>\r
789 <simpara>\r
790 C: copy of a file into a new one\r
791 </simpara>\r
792 </listitem>\r
793 <listitem>\r
794 <simpara>\r
795 D: deletion of a file\r
796 </simpara>\r
797 </listitem>\r
798 <listitem>\r
799 <simpara>\r
800 M: modification of the contents or mode of a file\r
801 </simpara>\r
802 </listitem>\r
803 <listitem>\r
804 <simpara>\r
805 R: renaming of a file\r
806 </simpara>\r
807 </listitem>\r
808 <listitem>\r
809 <simpara>\r
810 T: change in the type of the file\r
811 </simpara>\r
812 </listitem>\r
813 <listitem>\r
814 <simpara>\r
815 U: file is unmerged (you must complete the merge before it can\r
816 be committed)\r
817 </simpara>\r
818 </listitem>\r
819 <listitem>\r
820 <simpara>\r
821 X: "unknown" change type (most probably a bug, please report it)\r
822 </simpara>\r
823 </listitem>\r
824 </itemizedlist>\r
825 <simpara>Status letters C and R are always followed by a score (denoting the\r
826 percentage of similarity between the source and target of the move or\r
827 copy), and are the only ones to be so.</simpara>\r
828 <simpara>&lt;sha1&gt; is shown as all 0&#8217;s if a file is new on the filesystem\r
829 and it is out of sync with the index.</simpara>\r
830 <simpara>Example:</simpara>\r
831 <literallayout>:100644 100644 5be4a4...... 000000...... M file.c</literallayout>\r
832 <simpara>When <literal>-z</literal> option is not used, TAB, LF, and backslash characters\r
833 in pathnames are represented as <literal>\t</literal>, <literal>\n</literal>, and <literal>\\</literal>,\r
834 respectively.</simpara>\r
835 </simplesect>\r
836 <simplesect id="_diff_format_for_merges">\r
837 <title>diff format for merges</title>\r
838 <simpara>"git-diff-tree", "git-diff-files" and "git-diff --raw"\r
839 can take <emphasis>-c</emphasis> or <emphasis>--cc</emphasis> option\r
840 to generate diff output also for merge commits.  The output differs\r
841 from the format described above in the following way:</simpara>\r
842 <orderedlist numeration="arabic">\r
843 <listitem>\r
844 <simpara>\r
845 there is a colon for each parent\r
846 </simpara>\r
847 </listitem>\r
848 <listitem>\r
849 <simpara>\r
850 there are more "src" modes and "src" sha1\r
851 </simpara>\r
852 </listitem>\r
853 <listitem>\r
854 <simpara>\r
855 status is concatenated status characters for each parent\r
856 </simpara>\r
857 </listitem>\r
858 <listitem>\r
859 <simpara>\r
860 no optional "score" number\r
861 </simpara>\r
862 </listitem>\r
863 <listitem>\r
864 <simpara>\r
865 single path, only for "dst"\r
866 </simpara>\r
867 </listitem>\r
868 </orderedlist>\r
869 <simpara>Example:</simpara>\r
870 <literallayout>::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM      describe.c</literallayout>\r
871 <simpara>Note that <emphasis>combined diff</emphasis> lists only files which were modified from\r
872 all parents.</simpara>\r
873 </simplesect>\r
874 <simplesect id="_generating_patches_with_p">\r
875 <title>Generating patches with -p</title>\r
876 <simpara>When "git-diff-index", "git-diff-tree", or "git-diff-files" are run\r
877 with a <emphasis>-p</emphasis> option, "git diff" without the <emphasis>--raw</emphasis> option, or\r
878 "git log" with the "-p" option, they\r
879 do not produce the output described above; instead they produce a\r
880 patch file.  You can customize the creation of such patches via the\r
881 GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables.</simpara>\r
882 <simpara>What the -p option produces is slightly different from the traditional\r
883 diff format.</simpara>\r
884 <orderedlist numeration="arabic">\r
885 <listitem>\r
886 <simpara>\r
887 It is preceded with a "git diff" header, that looks like\r
888      this:\r
889 </simpara>\r
890 <literallayout class="monospaced">diff --git a/file1 b/file2</literallayout>\r
891 <simpara>The <literal>a/</literal> and <literal>b/</literal> filenames are the same unless rename/copy is\r
892 involved.  Especially, even for a creation or a deletion,\r
893 <literal>/dev/null</literal> is <emphasis>not</emphasis> used in place of <literal>a/</literal> or <literal>b/</literal> filenames.</simpara>\r
894 <simpara>When rename/copy is involved, <literal>file1</literal> and <literal>file2</literal> show the\r
895 name of the source file of the rename/copy and the name of\r
896 the file that rename/copy produces, respectively.</simpara>\r
897 </listitem>\r
898 <listitem>\r
899 <simpara>\r
900 It is followed by one or more extended header lines:\r
901 </simpara>\r
902 <literallayout class="monospaced">old mode &lt;mode&gt;\r
903 new mode &lt;mode&gt;\r
904 deleted file mode &lt;mode&gt;\r
905 new file mode &lt;mode&gt;\r
906 copy from &lt;path&gt;\r
907 copy to &lt;path&gt;\r
908 rename from &lt;path&gt;\r
909 rename to &lt;path&gt;\r
910 similarity index &lt;number&gt;\r
911 dissimilarity index &lt;number&gt;\r
912 index &lt;hash&gt;..&lt;hash&gt; &lt;mode&gt;</literallayout>\r
913 </listitem>\r
914 <listitem>\r
915 <simpara>\r
916 TAB, LF, double quote and backslash characters in pathnames\r
917     are represented as <literal>\t</literal>, <literal>\n</literal>, <literal>\"</literal> and <literal>\\</literal>, respectively.\r
918     If there is need for such substitution then the whole\r
919     pathname is put in double quotes.\r
920 </simpara>\r
921 </listitem>\r
922 </orderedlist>\r
923 <simpara>The similarity index is the percentage of unchanged lines, and\r
924 the dissimilarity index is the percentage of changed lines.  It\r
925 is a rounded down integer, followed by a percent sign.  The\r
926 similarity index value of 100% is thus reserved for two equal\r
927 files, while 100% dissimilarity means that no line from the old\r
928 file made it into the new one.</simpara>\r
929 </simplesect>\r
930 <simplesect id="_combined_diff_format">\r
931 <title>combined diff format</title>\r
932 <simpara>"git-diff-tree", "git-diff-files" and "git-diff" can take <emphasis>-c</emphasis> or\r
933 <emphasis>--cc</emphasis> option to produce <emphasis>combined diff</emphasis>.  For showing a merge commit\r
934 with "git log -p", this is the default format.\r
935 A <emphasis>combined diff</emphasis> format looks like this:</simpara>\r
936 <literallayout>diff --combined describe.c\r
937 index fabadb8,cc95eb0..4866510\r
938 --- a/describe.c\r
939 +++ b/describe.c\r
940 @@@ -98,20 -98,12 +98,20 @@@\r
941         return (a_date &gt; b_date) ? -1 : (a_date == b_date) ? 0 : 1;\r
942   }\r
943 \r
944 - static void describe(char *arg)\r
945  -static void describe(struct commit *cmit, int last_one)\r
946 ++static void describe(char *arg, int last_one)\r
947   {\r
948  +      unsigned char sha1[20];\r
949  +      struct commit *cmit;\r
950         struct commit_list *list;\r
951         static int initialized = 0;\r
952         struct commit_name *n;\r
953 \r
954  +      if (get_sha1(arg, sha1) &lt; 0)\r
955  +              usage(describe_usage);\r
956  +      cmit = lookup_commit_reference(sha1);\r
957  +      if (!cmit)\r
958  +              usage(describe_usage);\r
959  +\r
960         if (!initialized) {\r
961                 initialized = 1;\r
962                 for_each_ref(get_name);</literallayout>\r
963 <orderedlist numeration="arabic">\r
964 <listitem>\r
965 <simpara>\r
966 It is preceded with a "git diff" header, that looks like\r
967      this (when <emphasis>-c</emphasis> option is used):\r
968 </simpara>\r
969 <literallayout class="monospaced">diff --combined file</literallayout>\r
970 <simpara>or like this (when <emphasis>--cc</emphasis> option is used):</simpara>\r
971 <literallayout class="monospaced">diff --cc file</literallayout>\r
972 </listitem>\r
973 <listitem>\r
974 <simpara>\r
975 It is followed by one or more extended header lines\r
976      (this example shows a merge with two parents):\r
977 </simpara>\r
978 <literallayout class="monospaced">index &lt;hash&gt;,&lt;hash&gt;..&lt;hash&gt;\r
979 mode &lt;mode&gt;,&lt;mode&gt;..&lt;mode&gt;\r
980 new file mode &lt;mode&gt;\r
981 deleted file mode &lt;mode&gt;,&lt;mode&gt;</literallayout>\r
982 <simpara>The <literal>mode &lt;mode&gt;,&lt;mode&gt;..&lt;mode&gt;</literal> line appears only if at least one of\r
983 the &lt;mode&gt; is different from the rest. Extended headers with\r
984 information about detected contents movement (renames and\r
985 copying detection) are designed to work with diff of two\r
986 &lt;tree-ish&gt; and are not used by combined diff format.</simpara>\r
987 </listitem>\r
988 <listitem>\r
989 <simpara>\r
990 It is followed by two-line from-file/to-file header\r
991 </simpara>\r
992 <literallayout class="monospaced">--- a/file\r
993 +++ b/file</literallayout>\r
994 <simpara>Similar to two-line header for traditional <emphasis>unified</emphasis> diff\r
995 format, <literal>/dev/null</literal> is used to signal created or deleted\r
996 files.</simpara>\r
997 </listitem>\r
998 <listitem>\r
999 <simpara>\r
1000 Chunk header format is modified to prevent people from\r
1001      accidentally feeding it to <literal>patch -p1</literal>. Combined diff format\r
1002      was created for review of merge commit changes, and was not\r
1003      meant for apply. The change is similar to the change in the\r
1004      extended <emphasis>index</emphasis> header:\r
1005 </simpara>\r
1006 <literallayout class="monospaced">@@@ &lt;from-file-range&gt; &lt;from-file-range&gt; &lt;to-file-range&gt; @@@</literallayout>\r
1007 <simpara>There are (number of parents + 1) <literal>@</literal> characters in the chunk\r
1008 header for combined diff format.</simpara>\r
1009 </listitem>\r
1010 </orderedlist>\r
1011 <simpara>Unlike the traditional <emphasis>unified</emphasis> diff format, which shows two\r
1012 files A and B with a single column that has <literal>-</literal> (minus&#8201;&#8212;&#8201;appears in A but removed in B), <literal>+</literal> (plus&#8201;&#8212;&#8201;missing in A but\r
1013 added to B), or <literal>" "</literal> (space&#8201;&#8212;&#8201;unchanged) prefix, this format\r
1014 compares two or more files file1, file2,&#8230; with one file X, and\r
1015 shows how X differs from each of fileN.  One column for each of\r
1016 fileN is prepended to the output line to note how X&#8217;s line is\r
1017 different from it.</simpara>\r
1018 <simpara>A <literal>-</literal> character in the column N means that the line appears in\r
1019 fileN but it does not appear in the result.  A <literal>+</literal> character\r
1020 in the column N means that the line appears in the result,\r
1021 and fileN does not have that line (in other words, the line was\r
1022 added, from the point of view of that parent).</simpara>\r
1023 <simpara>In the above example output, the function signature was changed\r
1024 from both files (hence two <literal>-</literal> removals from both file1 and\r
1025 file2, plus <literal>++</literal> to mean one line that was added does not appear\r
1026 in either file1 nor file2).  Also eight other lines are the same\r
1027 from file1 but do not appear in file2 (hence prefixed with <literal>&#43;</literal>).</simpara>\r
1028 <simpara>When shown by <literal>git diff-tree -c</literal>, it compares the parents of a\r
1029 merge commit with the merge result (i.e. file1..fileN are the\r
1030 parents).  When shown by <literal>git diff-files -c</literal>, it compares the\r
1031 two unresolved merge parents with the working tree file\r
1032 (i.e. file1 is stage 2 aka "our version", file2 is stage 3 aka\r
1033 "their version").</simpara>\r
1034 </simplesect>\r
1035 <simplesect id="_other_diff_formats">\r
1036 <title>other diff formats</title>\r
1037 <simpara>The <literal>--summary</literal> option describes newly added, deleted, renamed and\r
1038 copied files.  The <literal>--stat</literal> option adds diffstat(1) graph to the\r
1039 output.  These options can be combined with other options, such as\r
1040 <literal>-p</literal>, and are meant for human consumption.</simpara>\r
1041 <simpara>When showing a change that involves a rename or a copy, <literal>--stat</literal> output\r
1042 formats the pathnames compactly by combining common prefix and suffix of\r
1043 the pathnames.  For example, a change that moves <literal>arch/i386/Makefile</literal> to\r
1044 <literal>arch/x86/Makefile</literal> while modifying 4 lines will be shown like this:</simpara>\r
1045 <literallayout>arch/{i386 =&gt; x86}/Makefile    |   4 +--</literallayout>\r
1046 <simpara>The <literal>--numstat</literal> option gives the diffstat(1) information but is designed\r
1047 for easier machine consumption.  An entry in <literal>--numstat</literal> output looks\r
1048 like this:</simpara>\r
1049 <literallayout>1       2       README\r
1050 3       1       arch/{i386 =&gt; x86}/Makefile</literallayout>\r
1051 <simpara>That is, from left to right:</simpara>\r
1052 <orderedlist numeration="arabic">\r
1053 <listitem>\r
1054 <simpara>\r
1055 the number of added lines;\r
1056 </simpara>\r
1057 </listitem>\r
1058 <listitem>\r
1059 <simpara>\r
1060 a tab;\r
1061 </simpara>\r
1062 </listitem>\r
1063 <listitem>\r
1064 <simpara>\r
1065 the number of deleted lines;\r
1066 </simpara>\r
1067 </listitem>\r
1068 <listitem>\r
1069 <simpara>\r
1070 a tab;\r
1071 </simpara>\r
1072 </listitem>\r
1073 <listitem>\r
1074 <simpara>\r
1075 pathname (possibly with rename/copy information);\r
1076 </simpara>\r
1077 </listitem>\r
1078 <listitem>\r
1079 <simpara>\r
1080 a newline.\r
1081 </simpara>\r
1082 </listitem>\r
1083 </orderedlist>\r
1084 <simpara>When <literal>-z</literal> output option is in effect, the output is formatted this way:</simpara>\r
1085 <literallayout>1       2       README NUL\r
1086 3       1       NUL arch/i386/Makefile NUL arch/x86/Makefile NUL</literallayout>\r
1087 <simpara>That is:</simpara>\r
1088 <orderedlist numeration="arabic">\r
1089 <listitem>\r
1090 <simpara>\r
1091 the number of added lines;\r
1092 </simpara>\r
1093 </listitem>\r
1094 <listitem>\r
1095 <simpara>\r
1096 a tab;\r
1097 </simpara>\r
1098 </listitem>\r
1099 <listitem>\r
1100 <simpara>\r
1101 the number of deleted lines;\r
1102 </simpara>\r
1103 </listitem>\r
1104 <listitem>\r
1105 <simpara>\r
1106 a tab;\r
1107 </simpara>\r
1108 </listitem>\r
1109 <listitem>\r
1110 <simpara>\r
1111 a NUL (only exists if renamed/copied);\r
1112 </simpara>\r
1113 </listitem>\r
1114 <listitem>\r
1115 <simpara>\r
1116 pathname in preimage;\r
1117 </simpara>\r
1118 </listitem>\r
1119 <listitem>\r
1120 <simpara>\r
1121 a NUL (only exists if renamed/copied);\r
1122 </simpara>\r
1123 </listitem>\r
1124 <listitem>\r
1125 <simpara>\r
1126 pathname in postimage (only exists if renamed/copied);\r
1127 </simpara>\r
1128 </listitem>\r
1129 <listitem>\r
1130 <simpara>\r
1131 a NUL.\r
1132 </simpara>\r
1133 </listitem>\r
1134 </orderedlist>\r
1135 <simpara>The extra <literal>NUL</literal> before the preimage path in renamed case is to allow\r
1136 scripts that read the output to tell if the current record being read is\r
1137 a single-path record or a rename/copy record without reading ahead.\r
1138 After reading added and deleted lines, reading up to <literal>NUL</literal> would yield\r
1139 the pathname, but if that is <literal>NUL</literal>, the record will show two paths.</simpara>\r
1140 </simplesect>\r
1141 <simplesect id="_operating_modes">\r
1142 <title>Operating Modes</title>\r
1143 <simpara>You can choose whether you want to trust the index file entirely\r
1144 (using the <emphasis>--cached</emphasis> flag) or ask the diff logic to show any files\r
1145 that don&#8217;t match the stat state as being "tentatively changed".  Both\r
1146 of these operations are very useful indeed.</simpara>\r
1147 </simplesect>\r
1148 <simplesect id="_cached_mode">\r
1149 <title>Cached Mode</title>\r
1150 <simpara>If <emphasis>--cached</emphasis> is specified, it allows you to ask:</simpara>\r
1151 <literallayout class="monospaced">show me the differences between HEAD and the current index\r
1152 contents (the ones I'd write using 'git-write-tree')</literallayout>\r
1153 <simpara>For example, let&#8217;s say that you have worked on your working directory, updated\r
1154 some files in the index and are ready to commit. You want to see exactly\r
1155 <emphasis role="strong">what</emphasis> you are going to commit, without having to write a new tree\r
1156 object and compare it that way, and to do that, you just do</simpara>\r
1157 <literallayout class="monospaced">git diff-index --cached HEAD</literallayout>\r
1158 <simpara>Example: let&#8217;s say I had renamed <literal>commit.c</literal> to <literal>git-commit.c</literal>, and I had\r
1159 done an <literal>update-index</literal> to make that effective in the index file.\r
1160 <literal>git diff-files</literal> wouldn&#8217;t show anything at all, since the index file\r
1161 matches my working directory. But doing a <emphasis>git-diff-index</emphasis> does:</simpara>\r
1162 <literallayout class="monospaced">torvalds@ppc970:~/git&gt; git diff-index --cached HEAD\r
1163 -100644 blob    4161aecc6700a2eb579e842af0b7f22b98443f74        commit.c\r
1164 +100644 blob    4161aecc6700a2eb579e842af0b7f22b98443f74        git-commit.c</literallayout>\r
1165 <simpara>You can see easily that the above is a rename.</simpara>\r
1166 <simpara>In fact, <literal>git diff-index --cached</literal> <emphasis role="strong">should</emphasis> always be entirely equivalent to\r
1167 actually doing a <emphasis>git-write-tree</emphasis> and comparing that. Except this one is much\r
1168 nicer for the case where you just want to check where you are.</simpara>\r
1169 <simpara>So doing a <emphasis>git-diff-index --cached</emphasis> is basically very useful when you are\r
1170 asking yourself "what have I already marked for being committed, and\r
1171 what&#8217;s the difference to a previous tree".</simpara>\r
1172 </simplesect>\r
1173 <simplesect id="_non_cached_mode">\r
1174 <title>Non-cached Mode</title>\r
1175 <simpara>The "non-cached" mode takes a different approach, and is potentially\r
1176 the more useful of the two in that what it does can&#8217;t be emulated with\r
1177 a <emphasis>git-write-tree</emphasis> + <emphasis>git-diff-tree</emphasis>. Thus that&#8217;s the default mode.\r
1178 The non-cached version asks the question:</simpara>\r
1179 <literallayout class="monospaced">show me the differences between HEAD and the currently checked out\r
1180 tree - index contents _and_ files that aren't up-to-date</literallayout>\r
1181 <simpara>which is obviously a very useful question too, since that tells you what\r
1182 you <emphasis role="strong">could</emphasis> commit. Again, the output matches the <emphasis>git-diff-tree -r</emphasis>\r
1183 output to a tee, but with a twist.</simpara>\r
1184 <simpara>The twist is that if some file doesn&#8217;t match the index, we don&#8217;t have\r
1185 a backing store thing for it, and we use the magic "all-zero" sha1 to\r
1186 show that. So let&#8217;s say that you have edited <literal>kernel/sched.c</literal>, but\r
1187 have not actually done a <emphasis>git-update-index</emphasis> on it yet - there is no\r
1188 "object" associated with the new state, and you get:</simpara>\r
1189 <literallayout class="monospaced">torvalds@ppc970:~/v2.6/linux&gt; git diff-index HEAD\r
1190 *100644-&gt;100664 blob    7476bb......-&gt;000000......      kernel/sched.c</literallayout>\r
1191 <simpara>i.e., it shows that the tree has changed, and that <literal>kernel/sched.c</literal> has is\r
1192 not up-to-date and may contain new stuff. The all-zero sha1 means that to\r
1193 get the real diff, you need to look at the object in the working directory\r
1194 directly rather than do an object-to-object diff.</simpara>\r
1195 <note><simpara>As with other commands of this type, <emphasis>git-diff-index</emphasis> does not\r
1196 actually look at the contents of the file at all. So maybe\r
1197 <literal>kernel/sched.c</literal> hasn&#8217;t actually changed, and it&#8217;s just that you\r
1198 touched it. In either case, it&#8217;s a note that you need to\r
1199 <emphasis>git-update-index</emphasis> it to make the index be in sync.</simpara></note>\r
1200 <note><simpara>You can have a mixture of files show up as "has been updated"\r
1201 and "is still dirty in the working directory" together. You can always\r
1202 tell which file is in which state, since the "has been updated" ones\r
1203 show a valid sha1, and the "not in sync with the index" ones will\r
1204 always have the special all-zero sha1.</simpara></note>\r
1205 </simplesect>\r
1206 <simplesect id="_author">\r
1207 <title>Author</title>\r
1208 <simpara>Written by Linus Torvalds &lt;<ulink url="mailto:torvalds@osdl.org">torvalds@osdl.org</ulink>&gt;</simpara>\r
1209 </simplesect>\r
1210 <simplesect id="_documentation">\r
1211 <title>Documentation</title>\r
1212 <simpara>Documentation by David Greaves, Junio C Hamano and the git-list &lt;<ulink url="mailto:git@vger.kernel.org">git@vger.kernel.org</ulink>&gt;.</simpara>\r
1213 </simplesect>\r
1214 <simplesect id="_git">\r
1215 <title>GIT</title>\r
1216 <simpara>Part of the <xref linkend="git(1)"/> suite</simpara>\r
1217 </simplesect>\r
1218 </article>\r