1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml" xml:
lang=
"en">
5 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8" />
6 <meta name=
"generator" content=
"AsciiDoc 8.2.5" />
7 <style type=
"text/css">
9 p
, li
, dt
, dd
, div
, pre
, h1
, h2
, h3
, h4
, h5
, h6
{
11 border: 1px solid red;
16 margin: 1em 5% 1em 5%;
21 text-decoration: underline
;
39 h1
, h2
, h3
, h4
, h5
, h6
{
41 font-family: sans-serif
;
48 border-bottom: 2px solid silver
;
66 border: 1px solid silver
;
81 font-family: sans-serif
;
88 font-family: sans-serif
;
92 font-family: sans-serif
;
94 border-top: 2px solid silver
;
100 padding-bottom: 0.5em;
104 padding-bottom: 0.5em;
108 div
.tableblock
, div
.imageblock
, div
.exampleblock
, div
.verseblock
,
109 div
.quoteblock
, div
.literalblock
, div
.listingblock
, div
.sidebarblock
,
110 div
.admonitionblock
{
113 margin-bottom: 1.5em;
115 div
.admonitionblock
{
117 margin-bottom: 2.5em;
120 div
.content
{ /* Block element content. */
124 /* Block element titles. */
125 div
.title
, caption
.title
{
126 font-family: sans-serif
;
130 margin-bottom: 0.5em;
136 td div
.title:first-child
{
139 div
.content div
.title:first-child
{
142 div
.content
+ div
.title
{
146 div
.sidebarblock
> div
.content
{
148 border: 1px solid silver
;
155 div
.listingblock
> div
.content
{
156 border: 1px solid silver
;
161 div
.quoteblock
> div
.content
{
168 div
.verseblock
+ div
.attribution
{
172 div
.admonitionblock
.icon
{
176 text-decoration: underline
;
178 padding-right: 0.5em;
180 div
.admonitionblock td
.content
{
182 border-left: 2px solid silver
;
185 div
.exampleblock
> div
.content
{
186 border-left: 2px solid silver
;
190 div
.verseblock div
.content
{
194 div
.imageblock div
.content
{ padding-left: 0; }
195 div
.imageblock img
{ border: 1px solid silver
; }
196 span
.image img
{ border-style: none
; }
200 margin-bottom: 0.8em;
212 list-style-position: outside
;
215 list-style-type: lower-alpha
;
218 div
.tableblock
> table
{
219 border: 3px solid
#527bbd;
222 font-family: sans-serif
;
231 margin-bottom: 0.8em;
239 padding-right: 0.8em;
246 div#footer-badges
{ display: none
; }
251 font-family: sans-serif
;
255 margin-bottom: 0.1em;
258 div
.toclevel1
, div
.toclevel2
, div
.toclevel3
, div
.toclevel4
{
274 include1::./stylesheets
/xhtml11-manpage
.css
[]
275 /* Workarounds for IE6's broken and incomplete CSS2. */
277 div
.sidebar-content
{
279 border: 1px solid silver
;
282 div
.sidebar-title
, div
.image-title
{
283 font-family: sans-serif
;
286 margin-bottom: 0.5em;
289 div
.listingblock div
.content
{
290 border: 1px solid silver
;
295 div
.quoteblock-content
{
299 div
.exampleblock-content
{
300 border-left: 2px solid silver
;
304 /* IE6 sets dynamically generated links as visited. */
305 div#toc
a:visited
{ color: blue
; }
307 <title>git-diff-index(
1)
</title>
312 git-diff-index(
1) Manual Page
315 <div class=
"sectionbody">
317 Compares content and mode of blobs between the index and repository
322 <div class=
"sectionbody">
323 <div class=
"para"><p><em>git diff-index
</em> [-m] [--cached] [
<common diff options
>]
<tree-ish
> [
<path
>…]
</p></div>
325 <h2 id=
"_description">DESCRIPTION
</h2>
326 <div class=
"sectionbody">
327 <div class=
"para"><p>Compares the content and mode of the blobs found via a tree
328 object with the content of the current index and, optionally
329 ignoring the stat state of the file on disk. When paths are
330 specified, compares only those named paths. Otherwise all
331 entries in the index are compared.
</p></div>
333 <h2 id=
"_options">OPTIONS
</h2>
334 <div class=
"sectionbody">
335 <div class=
"vlist"><dl>
344 Generate patch (see section on generating patches).
356 Generate diffs with
<n
> lines of context instead of
366 Generate the raw format.
375 Synonym for
<tt>-p --raw
</tt>.
383 Generate a diff using the
"patience diff" algorithm.
387 --stat[=width[,name-width]]
391 Generate a diffstat. You can override the default
392 output width for
80-column terminal by
<tt>--stat=width
</tt>.
393 The width of the filename part can be controlled by
394 giving another width to it separated by a comma.
402 Similar to
<tt>--stat
</tt>, but shows number of added and
403 deleted lines in decimal notation and pathname without
404 abbreviation, to make it more machine friendly. For
405 binary files, outputs two
<tt>-
</tt> instead of saying
414 Output only the last line of the
<tt>--stat
</tt> format containing total
415 number of modified files, as well as number of added and deleted
424 Output the distribution of relative amount of changes (number of lines added or
425 removed) for each sub-directory. Directories with changes below
426 a cut-off percent (
3% by default) are not shown. The cut-off percent
427 can be set with
<tt>--dirstat=limit
</tt>. Changes in a child directory is not
428 counted for the parent directory, unless
<tt>--cumulative
</tt> is used.
432 --dirstat-by-file[=limit]
436 Same as
<tt>--dirstat
</tt>, but counts changed files instead of lines.
444 Output a condensed summary of extended header information
445 such as creations, renames and mode changes.
453 Synonym for
<tt>-p --stat
</tt>.
461 When
<tt>--raw
</tt>,
<tt>--numstat
</tt>,
<tt>--name-only
</tt> or
<tt>--name-status
</tt> has been
462 given, do not munge pathnames and use NULs as output field terminators.
464 <div class=
"para"><p>Without this option, each pathname output will have TAB, LF, double quotes,
465 and backslash characters replaced with
<tt>\t
</tt>,
<tt>\n
</tt>,
<tt>\
"</tt>, and <tt>\\</tt>,
466 respectively, and the pathname will be enclosed in double quotes if
467 any of those replacements occurred.</p></div>
474 Show only names of changed files.
482 Show only names and status of changed files. See the description
483 of the <tt>--diff-filter</tt> option on what the status letters mean.
487 --submodule[=<format>]
491 Chose the output format for submodule differences. <format> can be one of
492 <em>short</em> and <em>log</em>. <em>short</em> just shows pairs of commit names, this format
493 is used when this option is not given. <em>log</em> is the default value for this
494 option and lists the commits in that commit range like the <em>summary</em>
495 option of <a href="git-submodule.html
">git-submodule(1)</a> does.
499 --color[=<when>]
504 The value must be always (the default), never, or auto.
512 Turn off colored diff, even when the configuration file
513 gives the default to color output.
514 Same as <tt>--color=never</tt>.
518 --color-words[=<regex>]
522 Show colored word diff, i.e., color words which have changed.
523 By default, words are separated by whitespace.
525 <div class="para
"><p>When a <regex> is specified, every non-overlapping match of the
526 <regex> is considered a word. Anything between these matches is
527 considered whitespace and ignored(!) for the purposes of finding
528 differences. You may want to append <tt>|[^[:space:]]</tt> to your regular
529 expression to make sure that it matches all non-whitespace characters.
530 A match that contains a newline is silently truncated(!) at the
532 <div class="para
"><p>The regex can also be set via a diff driver or configuration option, see
533 <a href="gitattributes.html
">gitattributes(1)</a> or <a href="git-config.html
">git-config(1)</a>. Giving it explicitly
534 overrides any diff driver or configuration setting. Diff drivers
535 override configuration settings.</p></div>
542 Turn off rename detection, even when the configuration
543 file gives the default to do so.
551 Warn if changes introduce trailing whitespace
552 or an indent that uses a space before a tab. Exits with
553 non-zero status if problems are found. Not compatible with
562 Instead of the first handful of characters, show the full
563 pre- and post-image blob object names on the "index
"
564 line when generating patch format output.
572 In addition to <tt>--full-index</tt>, output a binary diff that
573 can be applied with <tt>git-apply</tt>.
581 Instead of showing the full 40-byte hexadecimal object
582 name in diff-raw format output and diff-tree header
583 lines, show only a partial prefix. This is
584 independent of the <tt>--full-index</tt> option above, which controls
585 the diff-patch output format. Non default number of
586 digits can be specified with <tt>--abbrev=<n></tt>.
594 Break complete rewrite changes into pairs of delete and create.
610 Detect copies as well as renames. See also <tt>--find-copies-harder</tt>.
614 --diff-filter=[ACDMRTUXB*]
618 Select only files that are Added (<tt>A</tt>), Copied (<tt>C</tt>),
619 Deleted (<tt>D</tt>), Modified (<tt>M</tt>), Renamed (<tt>R</tt>), have their
620 type (i.e. regular file, symlink, submodule, …) changed (<tt>T</tt>),
621 are Unmerged (<tt>U</tt>), are
622 Unknown (<tt>X</tt>), or have had their pairing Broken (<tt>B</tt>).
623 Any combination of the filter characters may be used.
624 When <tt>*</tt> (All-or-none) is added to the combination, all
625 paths are selected if there is any file that matches
626 other criteria in the comparison; if there is no file
627 that matches other criteria, nothing is selected.
635 For performance reasons, by default, <tt>-C</tt> option finds copies only
636 if the original file of the copy was modified in the same
637 changeset. This flag makes the command
638 inspect unmodified files as candidates for the source of
639 copy. This is a very expensive operation for large
640 projects, so use it with caution. Giving more than one
641 <tt>-C</tt> option has the same effect.
649 The <tt>-M</tt> and <tt>-C</tt> options require O(n^2) processing time where n
650 is the number of potential rename/copy targets. This
651 option prevents rename/copy detection from running if
652 the number of rename/copy targets exceeds the specified
661 Look for differences that introduce or remove an instance of
662 <string>. Note that this is different than the string simply
663 appearing in diff output; see the <em>pickaxe</em> entry in
664 <a href="gitdiffcore.html
">gitdiffcore(7)</a> for more details.
672 When <tt>-S</tt> finds a change, show all the changes in that
673 changeset, not just the files that contain the change
682 Make the <string> not a plain string but an extended POSIX
691 Output the patch in the order specified in the
692 <orderfile>, which has one shell glob pattern per line.
700 Swap two inputs; that is, show differences from index or
701 on-disk file to tree contents.
705 --relative[=<path>]
709 When run from a subdirectory of the project, it can be
710 told to exclude changes outside the directory and show
711 pathnames relative to it with this option. When you are
712 not in a subdirectory (e.g. in a bare repository), you
713 can name which subdirectory to make the output relative
714 to by giving a <path> as an argument.
725 Treat all files as text.
729 --ignore-space-at-eol
733 Ignore changes in whitespace at EOL.
740 --ignore-space-change
744 Ignore changes in amount of whitespace. This ignores whitespace
745 at line end, and considers all other sequences of one or
746 more whitespace characters to be equivalent.
757 Ignore whitespace when comparing lines. This ignores
758 differences even if one line has whitespace where the other
763 --inter-hunk-context=<lines>
767 Show the context between diff hunks, up to the specified number
768 of lines, thereby fusing hunks that are close to each other.
776 Make the program exit with codes similar to diff(1).
777 That is, it exits with 1 if there were differences and
778 0 means no differences.
786 Disable all output of the program. Implies <tt>--exit-code</tt>.
794 Allow an external diff helper to be executed. If you set an
795 external diff driver with <a href="gitattributes.html
">gitattributes(5)</a>, you need
796 to use this option with <a href="git-log.html
">git-log(1)</a> and friends.
804 Disallow external diff drivers.
812 Ignore changes to submodules in the diff generation.
816 --src-prefix=<prefix>
820 Show the given source prefix instead of "a/
".
824 --dst-prefix=<prefix>
828 Show the given destination prefix instead of "b/
".
836 Do not show any source or destination prefix.
840 <div class="para
"><p>For more detailed explanation on these common options, see also
841 <a href="gitdiffcore.html
">gitdiffcore(7)</a>.</p></div>
842 <div class="vlist
"><dl>
848 The id of a tree object to diff against.
856 do not consider the on-disk file at all
864 By default, files recorded in the index but not checked
865 out are reported as deleted. This flag makes
866 <em>git diff-index</em> say that all non-checked-out files are up
872 <h2 id="_raw_output_format
">Raw output format</h2>
873 <div class="sectionbody
">
874 <div class="para
"><p>The raw output format from "git-diff-index
", "git-diff-tree
",
875 "git-diff-files
" and "git diff --raw
" are very similar.</p></div>
876 <div class="para
"><p>These commands all compare two sets of things; what is
877 compared differs:</p></div>
878 <div class="vlist
"><dl>
880 git-diff-index <tree-ish>
884 compares the <tree-ish> and the files on the filesystem.
888 git-diff-index --cached <tree-ish>
892 compares the <tree-ish> and the index.
896 git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>…]
900 compares the trees named by the two arguments.
904 git-diff-files [<pattern>…]
908 compares the index and the files on the filesystem.
912 <div class="para
"><p>The "git-diff-tree
" command begins its output by printing the hash of
913 what is being compared. After that, all the commands print one output
914 line per changed file.</p></div>
915 <div class="para
"><p>An output line is formatted this way:</p></div>
916 <div class="listingblock
">
917 <div class="content
">
918 <pre><tt>in-place edit :100644 100644 bcd1234... 0123456... M file0
919 copy-edit :100644 100644 abcd123... 1234567... C68 file1 file2
920 rename-edit :100644 100644 abcd123... 1234567... R86 file1 file3
921 create :000000 100644 0000000... 1234567... A file4
922 delete :100644 000000 1234567... 0000000... D file5
923 unmerged :000000 000000 0000000... 0000000... U file6</tt></pre>
925 <div class="para
"><p>That is, from the left to the right:</p></div>
926 <div class="olist
"><ol>
934 mode for "src
"; 000000 if creation or unmerged.
944 mode for "dst
"; 000000 if deletion or unmerged.
954 sha1 for "src
"; 0{40} if creation or unmerged.
964 sha1 for "dst
"; 0{40} if creation, unmerged or "look at work tree
".
974 status, followed by optional "score
" number.
979 a tab or a NUL when <em>-z</em> option is used.
989 a tab or a NUL when <em>-z</em> option is used; only exists for C or R.
994 path for "dst
"; only exists for C or R.
999 an LF or a NUL when <em>-z</em> option is used, to terminate the record.
1003 <div class="para
"><p>Possible status letters are:</p></div>
1004 <div class="ilist
"><ul>
1007 A: addition of a file
1012 C: copy of a file into a new one
1017 D: deletion of a file
1022 M: modification of the contents or mode of a file
1027 R: renaming of a file
1032 T: change in the type of the file
1037 U: file is unmerged (you must complete the merge before it can
1043 X: "unknown
" change type (most probably a bug, please report it)
1047 <div class="para
"><p>Status letters C and R are always followed by a score (denoting the
1048 percentage of similarity between the source and target of the move or
1049 copy), and are the only ones to be so.</p></div>
1050 <div class="para
"><p><sha1> is shown as all 0's if a file is new on the filesystem
1051 and it is out of sync with the index.</p></div>
1052 <div class="para
"><p>Example:</p></div>
1053 <div class="listingblock
">
1054 <div class="content
">
1055 <pre><tt>:100644 100644 5be4a4...... 000000...... M file.c</tt></pre>
1057 <div class="para
"><p>When <tt>-z</tt> option is not used, TAB, LF, and backslash characters
1058 in pathnames are represented as <tt>\t</tt>, <tt>\n</tt>, and <tt>\\</tt>,
1059 respectively.</p></div>
1061 <h2 id="_diff_format_for_merges
">diff format for merges</h2>
1062 <div class="sectionbody
">
1063 <div class="para
"><p>"git-diff-tree
", "git-diff-files
" and "git-diff --raw
"
1064 can take <em>-c</em> or <em>--cc</em> option
1065 to generate diff output also for merge commits. The output differs
1066 from the format described above in the following way:</p></div>
1067 <div class="olist
"><ol>
1070 there is a colon for each parent
1075 there are more "src
" modes and "src
" sha1
1080 status is concatenated status characters for each parent
1085 no optional "score
" number
1090 single path, only for "dst
"
1094 <div class="para
"><p>Example:</p></div>
1095 <div class="listingblock
">
1096 <div class="content
">
1097 <pre><tt>::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM describe.c</tt></pre>
1099 <div class="para
"><p>Note that <em>combined diff</em> lists only files which were modified from
1100 all parents.</p></div>
1102 <h2 id="_generating_patches_with_p
">Generating patches with -p</h2>
1103 <div class="sectionbody
">
1104 <div class="para
"><p>When "git-diff-index
", "git-diff-tree
", or "git-diff-files
" are run
1105 with a <em>-p</em> option, "git diff
" without the <em>--raw</em> option, or
1106 "git log
" with the "-p
" option, they
1107 do not produce the output described above; instead they produce a
1108 patch file. You can customize the creation of such patches via the
1109 GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables.</p></div>
1110 <div class="para
"><p>What the -p option produces is slightly different from the traditional
1111 diff format.</p></div>
1112 <div class="olist
"><ol>
1115 It is preceded with a "git diff
" header, that looks like
1118 <div class="literalblock
">
1119 <div class="content
">
1120 <pre><tt>diff --git a/file1 b/file2</tt></pre>
1122 <div class="para
"><p>The <tt>a/</tt> and <tt>b/</tt> filenames are the same unless rename/copy is
1123 involved. Especially, even for a creation or a deletion,
1124 <tt>/dev/null</tt> is _not_ used in place of <tt>a/</tt> or <tt>b/</tt> filenames.</p></div>
1125 <div class="para
"><p>When rename/copy is involved, <tt>file1</tt> and <tt>file2</tt> show the
1126 name of the source file of the rename/copy and the name of
1127 the file that rename/copy produces, respectively.</p></div>
1131 It is followed by one or more extended header lines:
1133 <div class="literalblock
">
1134 <div class="content
">
1135 <pre><tt>old mode <mode>
1136 new mode <mode>
1137 deleted file mode <mode>
1138 new file mode <mode>
1139 copy from <path>
1140 copy to <path>
1141 rename from <path>
1142 rename to <path>
1143 similarity index <number>
1144 dissimilarity index <number>
1145 index <hash>..<hash> <mode></tt></pre>
1150 TAB, LF, double quote and backslash characters in pathnames
1151 are represented as <tt>\t</tt>, <tt>\n</tt>, <tt>\"</tt> and
<tt>\\
</tt>, respectively.
1152 If there is need for such substitution then the whole
1153 pathname is put in double quotes.
1157 <div class=
"para"><p>The similarity index is the percentage of unchanged lines, and
1158 the dissimilarity index is the percentage of changed lines. It
1159 is a rounded down integer, followed by a percent sign. The
1160 similarity index value of
100% is thus reserved for two equal
1161 files, while
100% dissimilarity means that no line from the old
1162 file made it into the new one.
</p></div>
1164 <h2 id=
"_combined_diff_format">combined diff format
</h2>
1165 <div class=
"sectionbody">
1166 <div class=
"para"><p>"git-diff-tree",
"git-diff-files" and
"git-diff" can take
<em>-c
</em> or
1167 <em>--cc
</em> option to produce
<em>combined diff
</em>. For showing a merge commit
1168 with
"git log -p", this is the default format; you can force showing
1169 full diff with the
<em>-m
</em> option.
1170 A
<em>combined diff
</em> format looks like this:
</p></div>
1171 <div class=
"listingblock">
1172 <div class=
"content">
1173 <pre><tt>diff --combined describe.c
1174 index fabadb8,cc95eb0.
.4866510
1177 @@@ -
98,
20 -
98,
12 +
98,
20 @@@
1178 return (a_date
> b_date) ? -
1 : (a_date == b_date) ?
0 :
1;
1181 - static void describe(char *arg)
1182 -static void describe(struct commit *cmit, int last_one)
1183 ++static void describe(char *arg, int last_one)
1185 + unsigned char sha1[
20];
1186 + struct commit *cmit;
1187 struct commit_list *list;
1188 static int initialized =
0;
1189 struct commit_name *n;
1191 + if (get_sha1(arg, sha1)
< 0)
1192 + usage(describe_usage);
1193 + cmit = lookup_commit_reference(sha1);
1195 + usage(describe_usage);
1199 for_each_ref(get_name);
</tt></pre>
1201 <div class=
"olist"><ol>
1204 It is preceded with a
"git diff" header, that looks like
1205 this (when
<em>-c
</em> option is used):
1207 <div class=
"literalblock">
1208 <div class=
"content">
1209 <pre><tt>diff --combined file
</tt></pre>
1211 <div class=
"para"><p>or like this (when
<em>--cc
</em> option is used):
</p></div>
1212 <div class=
"literalblock">
1213 <div class=
"content">
1214 <pre><tt>diff --cc file
</tt></pre>
1219 It is followed by one or more extended header lines
1220 (this example shows a merge with two parents):
1222 <div class=
"literalblock">
1223 <div class=
"content">
1224 <pre><tt>index
<hash
>,
<hash
>..
<hash
>
1225 mode
<mode
>,
<mode
>..
<mode
>
1226 new file mode
<mode
>
1227 deleted file mode
<mode
>,
<mode
></tt></pre>
1229 <div class=
"para"><p>The
<tt>mode
<mode
>,
<mode
>..
<mode
></tt> line appears only if at least one of
1230 the
<mode
> is different from the rest. Extended headers with
1231 information about detected contents movement (renames and
1232 copying detection) are designed to work with diff of two
1233 <tree-ish
> and are not used by combined diff format.
</p></div>
1237 It is followed by two-line from-file/to-file header
1239 <div class=
"literalblock">
1240 <div class=
"content">
1242 +++ b/file
</tt></pre>
1244 <div class=
"para"><p>Similar to two-line header for traditional
<em>unified
</em> diff
1245 format,
<tt>/dev/null
</tt> is used to signal created or deleted
1250 Chunk header format is modified to prevent people from
1251 accidentally feeding it to
<tt>patch -p1
</tt>. Combined diff format
1252 was created for review of merge commit changes, and was not
1253 meant for apply. The change is similar to the change in the
1254 extended
<em>index
</em> header:
1256 <div class=
"literalblock">
1257 <div class=
"content">
1258 <pre><tt>@@@
<from-file-range
> <from-file-range
> <to-file-range
> @@@
</tt></pre>
1260 <div class=
"para"><p>There are (number of parents +
1)
<tt>@
</tt> characters in the chunk
1261 header for combined diff format.
</p></div>
1264 <div class=
"para"><p>Unlike the traditional
<em>unified
</em> diff format, which shows two
1265 files A and B with a single column that has
<tt>-
</tt> (minus
—
1266 appears in A but removed in B),
<tt>+
</tt> (plus
— missing in A but
1267 added to B), or
<tt>" "</tt> (space
— unchanged) prefix, this format
1268 compares two or more files file1, file2,
… with one file X, and
1269 shows how X differs from each of fileN. One column for each of
1270 fileN is prepended to the output line to note how X's line is
1271 different from it.
</p></div>
1272 <div class=
"para"><p>A
<tt>-
</tt> character in the column N means that the line appears in
1273 fileN but it does not appear in the result. A
<tt>+
</tt> character
1274 in the column N means that the line appears in the result,
1275 and fileN does not have that line (in other words, the line was
1276 added, from the point of view of that parent).
</p></div>
1277 <div class=
"para"><p>In the above example output, the function signature was changed
1278 from both files (hence two
<tt>-
</tt> removals from both file1 and
1279 file2, plus
<tt>++
</tt> to mean one line that was added does not appear
1280 in either file1 nor file2). Also eight other lines are the same
1281 from file1 but do not appear in file2 (hence prefixed with
<tt>+</tt>).
</p></div>
1282 <div class=
"para"><p>When shown by
<tt>git diff-tree -c
</tt>, it compares the parents of a
1283 merge commit with the merge result (i.e. file1..fileN are the
1284 parents). When shown by
<tt>git diff-files -c
</tt>, it compares the
1285 two unresolved merge parents with the working tree file
1286 (i.e. file1 is stage
2 aka
"our version", file2 is stage
3 aka
1287 "their version").
</p></div>
1289 <h2 id=
"_other_diff_formats">other diff formats
</h2>
1290 <div class=
"sectionbody">
1291 <div class=
"para"><p>The
<tt>--summary
</tt> option describes newly added, deleted, renamed and
1292 copied files. The
<tt>--stat
</tt> option adds diffstat(
1) graph to the
1293 output. These options can be combined with other options, such as
1294 <tt>-p
</tt>, and are meant for human consumption.
</p></div>
1295 <div class=
"para"><p>When showing a change that involves a rename or a copy,
<tt>--stat
</tt> output
1296 formats the pathnames compactly by combining common prefix and suffix of
1297 the pathnames. For example, a change that moves
<tt>arch/i386/Makefile
</tt> to
1298 <tt>arch/x86/Makefile
</tt> while modifying
4 lines will be shown like this:
</p></div>
1299 <div class=
"listingblock">
1300 <div class=
"content">
1301 <pre><tt>arch/{i386 =
> x86}/Makefile |
4 +--
</tt></pre>
1303 <div class=
"para"><p>The
<tt>--numstat
</tt> option gives the diffstat(
1) information but is designed
1304 for easier machine consumption. An entry in
<tt>--numstat
</tt> output looks
1305 like this:
</p></div>
1306 <div class=
"listingblock">
1307 <div class=
"content">
1309 3 1 arch/{i386 =
> x86}/Makefile
</tt></pre>
1311 <div class=
"para"><p>That is, from left to right:
</p></div>
1312 <div class=
"olist"><ol>
1315 the number of added lines;
1325 the number of deleted lines;
1335 pathname (possibly with rename/copy information);
1344 <div class=
"para"><p>When
<tt>-z
</tt> output option is in effect, the output is formatted this way:
</p></div>
1345 <div class=
"listingblock">
1346 <div class=
"content">
1347 <pre><tt>1 2 README NUL
1348 3 1 NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
</tt></pre>
1350 <div class=
"para"><p>That is:
</p></div>
1351 <div class=
"olist"><ol>
1354 the number of added lines;
1364 the number of deleted lines;
1374 a NUL (only exists if renamed/copied);
1379 pathname in preimage;
1384 a NUL (only exists if renamed/copied);
1389 pathname in postimage (only exists if renamed/copied);
1398 <div class=
"para"><p>The extra
<tt>NUL
</tt> before the preimage path in renamed case is to allow
1399 scripts that read the output to tell if the current record being read is
1400 a single-path record or a rename/copy record without reading ahead.
1401 After reading added and deleted lines, reading up to
<tt>NUL
</tt> would yield
1402 the pathname, but if that is
<tt>NUL
</tt>, the record will show two paths.
</p></div>
1404 <h2 id=
"_operating_modes">Operating Modes
</h2>
1405 <div class=
"sectionbody">
1406 <div class=
"para"><p>You can choose whether you want to trust the index file entirely
1407 (using the
<em>--cached
</em> flag) or ask the diff logic to show any files
1408 that don't match the stat state as being
"tentatively changed". Both
1409 of these operations are very useful indeed.
</p></div>
1411 <h2 id=
"_cached_mode">Cached Mode
</h2>
1412 <div class=
"sectionbody">
1413 <div class=
"para"><p>If
<em>--cached
</em> is specified, it allows you to ask:
</p></div>
1414 <div class=
"literalblock">
1415 <div class=
"content">
1416 <pre><tt>show me the differences between HEAD and the current index
1417 contents (the ones I'd write using 'git write-tree')
</tt></pre>
1419 <div class=
"para"><p>For example, let's say that you have worked on your working directory, updated
1420 some files in the index and are ready to commit. You want to see exactly
1421 <strong>what
</strong> you are going to commit, without having to write a new tree
1422 object and compare it that way, and to do that, you just do
</p></div>
1423 <div class=
"literalblock">
1424 <div class=
"content">
1425 <pre><tt>git diff-index --cached HEAD
</tt></pre>
1427 <div class=
"para"><p>Example: let's say I had renamed
<tt>commit.c
</tt> to
<tt>git-commit.c
</tt>, and I had
1428 done an
<tt>update-index
</tt> to make that effective in the index file.
1429 <tt>git diff-files
</tt> wouldn't show anything at all, since the index file
1430 matches my working directory. But doing a
<em>git diff-index
</em> does:
</p></div>
1431 <div class=
"literalblock">
1432 <div class=
"content">
1433 <pre><tt>torvalds@ppc970:~/git
> git diff-index --cached HEAD
1434 -
100644 blob
4161aecc6700a2eb579e842af0b7f22b98443f74 commit.c
1435 +
100644 blob
4161aecc6700a2eb579e842af0b7f22b98443f74 git-commit.c
</tt></pre>
1437 <div class=
"para"><p>You can see easily that the above is a rename.
</p></div>
1438 <div class=
"para"><p>In fact,
<tt>git diff-index --cached
</tt> <strong>should
</strong> always be entirely equivalent to
1439 actually doing a
<em>git write-tree
</em> and comparing that. Except this one is much
1440 nicer for the case where you just want to check where you are.
</p></div>
1441 <div class=
"para"><p>So doing a
<tt>git diff-index --cached
</tt> is basically very useful when you are
1442 asking yourself
"what have I already marked for being committed, and
1443 what's the difference to a previous tree".
</p></div>
1445 <h2 id=
"_non_cached_mode">Non-cached Mode
</h2>
1446 <div class=
"sectionbody">
1447 <div class=
"para"><p>The
"non-cached" mode takes a different approach, and is potentially
1448 the more useful of the two in that what it does can't be emulated with
1449 a
<em>git write-tree
</em> +
<em>git diff-tree
</em>. Thus that's the default mode.
1450 The non-cached version asks the question:
</p></div>
1451 <div class=
"literalblock">
1452 <div class=
"content">
1453 <pre><tt>show me the differences between HEAD and the currently checked out
1454 tree - index contents _and_ files that aren't up-to-date
</tt></pre>
1456 <div class=
"para"><p>which is obviously a very useful question too, since that tells you what
1457 you
<strong>could
</strong> commit. Again, the output matches the
<em>git diff-tree -r
</em>
1458 output to a tee, but with a twist.
</p></div>
1459 <div class=
"para"><p>The twist is that if some file doesn't match the index, we don't have
1460 a backing store thing for it, and we use the magic
"all-zero" sha1 to
1461 show that. So let's say that you have edited
<tt>kernel/sched.c
</tt>, but
1462 have not actually done a
<em>git update-index
</em> on it yet - there is no
1463 "object" associated with the new state, and you get:
</p></div>
1464 <div class=
"literalblock">
1465 <div class=
"content">
1466 <pre><tt>torvalds@ppc970:~/v2.6/linux
> git diff-index HEAD
1467 *
100644-
>100664 blob
7476bb......-
>000000...... kernel/sched.c
</tt></pre>
1469 <div class=
"para"><p>i.e., it shows that the tree has changed, and that
<tt>kernel/sched.c
</tt> has is
1470 not up-to-date and may contain new stuff. The all-zero sha1 means that to
1471 get the real diff, you need to look at the object in the working directory
1472 directly rather than do an object-to-object diff.
</p></div>
1473 <div class=
"admonitionblock">
1476 <div class=
"title">Note
</div>
1478 <td class=
"content">As with other commands of this type,
<em>git diff-index
</em> does not
1479 actually look at the contents of the file at all. So maybe
1480 <tt>kernel/sched.c
</tt> hasn't actually changed, and it's just that you
1481 touched it. In either case, it's a note that you need to
1482 <em>git update-index
</em> it to make the index be in sync.
</td>
1485 <div class=
"admonitionblock">
1488 <div class=
"title">Note
</div>
1490 <td class=
"content">You can have a mixture of files show up as
"has been updated"
1491 and
"is still dirty in the working directory" together. You can always
1492 tell which file is in which state, since the
"has been updated" ones
1493 show a valid sha1, and the
"not in sync with the index" ones will
1494 always have the special all-zero sha1.
</td>
1498 <h2 id=
"_author">Author
</h2>
1499 <div class=
"sectionbody">
1500 <div class=
"para"><p>Written by Linus Torvalds
<torvalds@osdl.org
></p></div>
1502 <h2 id=
"_documentation">Documentation
</h2>
1503 <div class=
"sectionbody">
1504 <div class=
"para"><p>Documentation by David Greaves, Junio C Hamano and the git-list
<git@vger.kernel.org
>.
</p></div>
1506 <h2 id=
"_git">GIT
</h2>
1507 <div class=
"sectionbody">
1508 <div class=
"para"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
1511 <div id=
"footer-text">
1512 Last updated
2010-
04-
24 02:
55:
52 UTC