1GIT-DIFF-INDEX(1) Git Manual GIT-DIFF-INDEX(1)
2
3
4
6 git-diff-index - Compares content and mode of blobs between the index
7 and repository
8
10 git diff-index [-m] [--cached] [<common diff options>] <tree-ish>
11 [<path>...]
12
14 Compares the content and mode of the blobs found via a tree object with
15 the content of the current index and, optionally ignoring the stat
16 state of the file on disk. When paths are specified, compares only
17 those named paths. Otherwise all entries in the index are compared.
18
20 -p, -u, --patch
21 Generate patch (see section on generating patches).
22
23 -U<n>, --unified=<n>
24 Generate diffs with <n> lines of context instead of the usual
25 three. Implies -p.
26
27 --raw
28 Generate the raw format. This is the default.
29
30 --patch-with-raw
31 Synonym for -p --raw.
32
33 --patience
34 Generate a diff using the "patience diff" algorithm.
35
36 --stat[=<width>[,<name-width>]]
37 Generate a diffstat. You can override the default output width for
38 80-column terminal by --stat=<width>. The width of the filename
39 part can be controlled by giving another width to it separated by a
40 comma.
41
42 --numstat
43 Similar to --stat, but shows number of added and deleted lines in
44 decimal notation and pathname without abbreviation, to make it more
45 machine friendly. For binary files, outputs two - instead of saying
46 0 0.
47
48 --shortstat
49 Output only the last line of the --stat format containing total
50 number of modified files, as well as number of added and deleted
51 lines.
52
53 --dirstat[=<limit>]
54 Output the distribution of relative amount of changes (number of
55 lines added or removed) for each sub-directory. Directories with
56 changes below a cut-off percent (3% by default) are not shown. The
57 cut-off percent can be set with --dirstat=<limit>. Changes in a
58 child directory are not counted for the parent directory, unless
59 --cumulative is used.
60
61 --dirstat-by-file[=<limit>]
62 Same as --dirstat, but counts changed files instead of lines.
63
64 --summary
65 Output a condensed summary of extended header information such as
66 creations, renames and mode changes.
67
68 --patch-with-stat
69 Synonym for -p --stat.
70
71 -z
72 When --raw, --numstat, --name-only or --name-status has been given,
73 do not munge pathnames and use NULs as output field terminators.
74
75 Without this option, each pathname output will have TAB, LF, double
76 quotes, and backslash characters replaced with \t, \n, \", and \\,
77 respectively, and the pathname will be enclosed in double quotes if
78 any of those replacements occurred.
79
80 --name-only
81 Show only names of changed files.
82
83 --name-status
84 Show only names and status of changed files. See the description of
85 the --diff-filter option on what the status letters mean.
86
87 --submodule[=<format>]
88 Chose the output format for submodule differences. <format> can be
89 one of short and log. short just shows pairs of commit names, this
90 format is used when this option is not given. log is the default
91 value for this option and lists the commits in that commit range
92 like the summary option of git-submodule(1) does.
93
94 --color[=<when>]
95 Show colored diff. The value must be always (the default), never,
96 or auto.
97
98 --no-color
99 Turn off colored diff, even when the configuration file gives the
100 default to color output. Same as --color=never.
101
102 --word-diff[=<mode>]
103 Show a word diff, using the <mode> to delimit changed words. By
104 default, words are delimited by whitespace; see --word-diff-regex
105 below. The <mode> defaults to plain, and must be one of:
106
107 color
108 Highlight changed words using only colors. Implies --color.
109
110 plain
111 Show words as [-removed-] and {added}. Makes no attempts to
112 escape the delimiters if they appear in the input, so the
113 output may be ambiguous.
114
115 porcelain
116 Use a special line-based format intended for script
117 consumption. Added/removed/unchanged runs are printed in the
118 usual unified diff format, starting with a +/-/` ` character at
119 the beginning of the line and extending to the end of the line.
120 Newlines in the input are represented by a tilde ~ on a line of
121 its own.
122
123 none
124 Disable word diff again.
125
126 Note that despite the name of the first mode, color is used to
127 highlight the changed parts in all modes if enabled.
128
129 --word-diff-regex=<regex>
130 Use <regex> to decide what a word is, instead of considering runs
131 of non-whitespace to be a word. Also implies --word-diff unless it
132 was already enabled.
133
134 Every non-overlapping match of the <regex> is considered a word.
135 Anything between these matches is considered whitespace and
136 ignored(!) for the purposes of finding differences. You may want to
137 append |[^[:space:]] to your regular expression to make sure that
138 it matches all non-whitespace characters. A match that contains a
139 newline is silently truncated(!) at the newline.
140
141 The regex can also be set via a diff driver or configuration
142 option, see gitattributes(1) or git-config(1). Giving it explicitly
143 overrides any diff driver or configuration setting. Diff drivers
144 override configuration settings.
145
146 --color-words[=<regex>]
147 Equivalent to --word-diff=color plus (if a regex was specified)
148 --word-diff-regex=<regex>.
149
150 --no-renames
151 Turn off rename detection, even when the configuration file gives
152 the default to do so.
153
154 --check
155 Warn if changes introduce trailing whitespace or an indent that
156 uses a space before a tab. Exits with non-zero status if problems
157 are found. Not compatible with --exit-code.
158
159 --full-index
160 Instead of the first handful of characters, show the full pre- and
161 post-image blob object names on the "index" line when generating
162 patch format output.
163
164 --binary
165 In addition to --full-index, output a binary diff that can be
166 applied with git-apply.
167
168 --abbrev[=<n>]
169 Instead of showing the full 40-byte hexadecimal object name in
170 diff-raw format output and diff-tree header lines, show only a
171 partial prefix. This is independent of the --full-index option
172 above, which controls the diff-patch output format. Non default
173 number of digits can be specified with --abbrev=<n>.
174
175 -B[<n>][/<m>], --break-rewrites[=[<n>][/<m>]]
176 Break complete rewrite changes into pairs of delete and create.
177 This serves two purposes:
178
179 It affects the way a change that amounts to a total rewrite of a
180 file not as a series of deletion and insertion mixed together with
181 a very few lines that happen to match textually as the context, but
182 as a single deletion of everything old followed by a single
183 insertion of everything new, and the number m controls this aspect
184 of the -B option (defaults to 60%). -B/70% specifies that less
185 than 30% of the original should remain in the result for git to
186 consider it a total rewrite (i.e. otherwise the resulting patch
187 will be a series of deletion and insertion mixed together with
188 context lines).
189
190 When used with -M, a totally-rewritten file is also considered as
191 the source of a rename (usually -M only considers a file that
192 disappeared as the source of a rename), and the number n controls
193 this aspect of the -B option (defaults to 50%). -B20% specifies
194 that a change with addition and deletion compared to 20% or more of
195 the file’s size are eligible for being picked up as a possible
196 source of a rename to another file.
197
198 -M[<n>], --find-renames[=<n>]
199 Detect renames. If n is specified, it is a is a threshold on the
200 similarity index (i.e. amount of addition/deletions compared to the
201 file’s size). For example, -M90% means git should consider a
202 delete/add pair to be a rename if more than 90% of the file hasn’t
203 changed.
204
205 -C[<n>], --find-copies[=<n>]
206 Detect copies as well as renames. See also --find-copies-harder. If
207 n is specified, it has the same meaning as for -M<n>.
208
209 --find-copies-harder
210 For performance reasons, by default, -C option finds copies only if
211 the original file of the copy was modified in the same changeset.
212 This flag makes the command inspect unmodified files as candidates
213 for the source of copy. This is a very expensive operation for
214 large projects, so use it with caution. Giving more than one -C
215 option has the same effect.
216
217 -l<num>
218 The -M and -C options require O(n^2) processing time where n is the
219 number of potential rename/copy targets. This option prevents
220 rename/copy detection from running if the number of rename/copy
221 targets exceeds the specified number.
222
223 --diff-filter=[(A|C|D|M|R|T|U|X|B)...[*]]
224 Select only files that are Added (A), Copied (C), Deleted (D),
225 Modified (M), Renamed (R), have their type (i.e. regular file,
226 symlink, submodule, ...) changed (T), are Unmerged (U), are Unknown
227 (X), or have had their pairing Broken (B). Any combination of the
228 filter characters (including none) can be used. When *
229 (All-or-none) is added to the combination, all paths are selected
230 if there is any file that matches other criteria in the comparison;
231 if there is no file that matches other criteria, nothing is
232 selected.
233
234 -S<string>
235 Look for differences that introduce or remove an instance of
236 <string>. Note that this is different than the string simply
237 appearing in diff output; see the pickaxe entry in gitdiffcore(7)
238 for more details.
239
240 -G<regex>
241 Look for differences whose added or removed line matches the given
242 <regex>.
243
244 --pickaxe-all
245 When -S or -G finds a change, show all the changes in that
246 changeset, not just the files that contain the change in <string>.
247
248 --pickaxe-regex
249 Make the <string> not a plain string but an extended POSIX regex to
250 match.
251
252 -O<orderfile>
253 Output the patch in the order specified in the <orderfile>, which
254 has one shell glob pattern per line.
255
256 -R
257 Swap two inputs; that is, show differences from index or on-disk
258 file to tree contents.
259
260 --relative[=<path>]
261 When run from a subdirectory of the project, it can be told to
262 exclude changes outside the directory and show pathnames relative
263 to it with this option. When you are not in a subdirectory (e.g. in
264 a bare repository), you can name which subdirectory to make the
265 output relative to by giving a <path> as an argument.
266
267 -a, --text
268 Treat all files as text.
269
270 --ignore-space-at-eol
271 Ignore changes in whitespace at EOL.
272
273 -b, --ignore-space-change
274 Ignore changes in amount of whitespace. This ignores whitespace at
275 line end, and considers all other sequences of one or more
276 whitespace characters to be equivalent.
277
278 -w, --ignore-all-space
279 Ignore whitespace when comparing lines. This ignores differences
280 even if one line has whitespace where the other line has none.
281
282 --inter-hunk-context=<lines>
283 Show the context between diff hunks, up to the specified number of
284 lines, thereby fusing hunks that are close to each other.
285
286 --exit-code
287 Make the program exit with codes similar to diff(1). That is, it
288 exits with 1 if there were differences and 0 means no differences.
289
290 --quiet
291 Disable all output of the program. Implies --exit-code.
292
293 --ext-diff
294 Allow an external diff helper to be executed. If you set an
295 external diff driver with gitattributes(5), you need to use this
296 option with git-log(1) and friends.
297
298 --no-ext-diff
299 Disallow external diff drivers.
300
301 --ignore-submodules[=<when>]
302 Ignore changes to submodules in the diff generation. <when> can be
303 either "none", "untracked", "dirty" or "all", which is the default
304 Using "none" will consider the submodule modified when it either
305 contains untracked or modified files or its HEAD differs from the
306 commit recorded in the superproject and can be used to override any
307 settings of the ignore option in git-config(1) or gitmodules(5).
308 When "untracked" is used submodules are not considered dirty when
309 they only contain untracked content (but they are still scanned for
310 modified content). Using "dirty" ignores all changes to the work
311 tree of submodules, only changes to the commits stored in the
312 superproject are shown (this was the behavior until 1.7.0). Using
313 "all" hides all changes to submodules.
314
315 --src-prefix=<prefix>
316 Show the given source prefix instead of "a/".
317
318 --dst-prefix=<prefix>
319 Show the given destination prefix instead of "b/".
320
321 --no-prefix
322 Do not show any source or destination prefix.
323
324 For more detailed explanation on these common options, see also
325 gitdiffcore(7).
326
327 <tree-ish>
328 The id of a tree object to diff against.
329
330 --cached
331 do not consider the on-disk file at all
332
333 -m
334 By default, files recorded in the index but not checked out are
335 reported as deleted. This flag makes git diff-index say that all
336 non-checked-out files are up to date.
337
339 The raw output format from "git-diff-index", "git-diff-tree",
340 "git-diff-files" and "git diff --raw" are very similar.
341
342 These commands all compare two sets of things; what is compared
343 differs:
344
345 git-diff-index <tree-ish>
346 compares the <tree-ish> and the files on the filesystem.
347
348 git-diff-index --cached <tree-ish>
349 compares the <tree-ish> and the index.
350
351 git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]
352 compares the trees named by the two arguments.
353
354 git-diff-files [<pattern>...]
355 compares the index and the files on the filesystem.
356
357 The "git-diff-tree" command begins its output by printing the hash of
358 what is being compared. After that, all the commands print one output
359 line per changed file.
360
361 An output line is formatted this way:
362
363 in-place edit :100644 100644 bcd1234... 0123456... M file0
364 copy-edit :100644 100644 abcd123... 1234567... C68 file1 file2
365 rename-edit :100644 100644 abcd123... 1234567... R86 file1 file3
366 create :000000 100644 0000000... 1234567... A file4
367 delete :100644 000000 1234567... 0000000... D file5
368 unmerged :000000 000000 0000000... 0000000... U file6
369
370
371 That is, from the left to the right:
372
373 1. a colon.
374
375 2. mode for "src"; 000000 if creation or unmerged.
376
377 3. a space.
378
379 4. mode for "dst"; 000000 if deletion or unmerged.
380
381 5. a space.
382
383 6. sha1 for "src"; 0{40} if creation or unmerged.
384
385 7. a space.
386
387 8. sha1 for "dst"; 0{40} if creation, unmerged or "look at work tree".
388
389 9. a space.
390
391 10. status, followed by optional "score" number.
392
393 11. a tab or a NUL when -z option is used.
394
395 12. path for "src"
396
397 13. a tab or a NUL when -z option is used; only exists for C or R.
398
399 14. path for "dst"; only exists for C or R.
400
401 15. an LF or a NUL when -z option is used, to terminate the record.
402
403 Possible status letters are:
404
405 · A: addition of a file
406
407 · C: copy of a file into a new one
408
409 · D: deletion of a file
410
411 · M: modification of the contents or mode of a file
412
413 · R: renaming of a file
414
415 · T: change in the type of the file
416
417 · U: file is unmerged (you must complete the merge before it can be
418 committed)
419
420 · X: "unknown" change type (most probably a bug, please report it)
421
422 Status letters C and R are always followed by a score (denoting the
423 percentage of similarity between the source and target of the move or
424 copy), and are the only ones to be so.
425
426 <sha1> is shown as all 0’s if a file is new on the filesystem and it is
427 out of sync with the index.
428
429 Example:
430
431 :100644 100644 5be4a4...... 000000...... M file.c
432
433
434 When -z option is not used, TAB, LF, and backslash characters in
435 pathnames are represented as \t, \n, and \\, respectively.
436
438 "git-diff-tree", "git-diff-files" and "git-diff --raw" can take -c or
439 --cc option to generate diff output also for merge commits. The output
440 differs from the format described above in the following way:
441
442 1. there is a colon for each parent
443
444 2. there are more "src" modes and "src" sha1
445
446 3. status is concatenated status characters for each parent
447
448 4. no optional "score" number
449
450 5. single path, only for "dst"
451
452 Example:
453
454 ::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM describe.c
455
456
457 Note that combined diff lists only files which were modified from all
458 parents.
459
461 When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
462 with a -p option, "git diff" without the --raw option, or "git log"
463 with the "-p" option, they do not produce the output described above;
464 instead they produce a patch file. You can customize the creation of
465 such patches via the GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS
466 environment variables.
467
468 What the -p option produces is slightly different from the traditional
469 diff format:
470
471 1. It is preceded with a "git diff" header that looks like this:
472
473 diff --git a/file1 b/file2
474
475 The a/ and b/ filenames are the same unless rename/copy is
476 involved. Especially, even for a creation or a deletion, /dev/null
477 is not used in place of the a/ or b/ filenames.
478
479 When rename/copy is involved, file1 and file2 show the name of the
480 source file of the rename/copy and the name of the file that
481 rename/copy produces, respectively.
482
483 2. It is followed by one or more extended header lines:
484
485 old mode <mode>
486 new mode <mode>
487 deleted file mode <mode>
488 new file mode <mode>
489 copy from <path>
490 copy to <path>
491 rename from <path>
492 rename to <path>
493 similarity index <number>
494 dissimilarity index <number>
495 index <hash>..<hash> <mode>
496
497 File modes are printed as 6-digit octal numbers including the file
498 type and file permission bits.
499
500 Path names in extended headers do not include the a/ and b/
501 prefixes.
502
503 The similarity index is the percentage of unchanged lines, and the
504 dissimilarity index is the percentage of changed lines. It is a
505 rounded down integer, followed by a percent sign. The similarity
506 index value of 100% is thus reserved for two equal files, while
507 100% dissimilarity means that no line from the old file made it
508 into the new one.
509
510 The index line includes the SHA-1 checksum before and after the
511 change. The <mode> is included if the file mode does not change;
512 otherwise, separate lines indicate the old and the new mode.
513
514 3. TAB, LF, double quote and backslash characters in pathnames are
515 represented as \t, \n, \" and \\, respectively. If there is need
516 for such substitution then the whole pathname is put in double
517 quotes.
518
519 4. All the file1 files in the output refer to files before the commit,
520 and all the file2 files refer to files after the commit. It is
521 incorrect to apply each change to each file sequentially. For
522 example, this patch will swap a and b:
523
524 diff --git a/a b/b
525 rename from a
526 rename to b
527 diff --git a/b b/a
528 rename from b
529 rename to a
530
532 Any diff-generating command can take the ‘-c` or --cc option to produce
533 a combined diff when showing a merge. This is the default format when
534 showing merges with git-diff(1) or git-show(1). Note also that you can
535 give the `-m’ option to any of these commands to force generation of
536 diffs with individual parents of a merge.
537
538 A combined diff format looks like this:
539
540 diff --combined describe.c
541 index fabadb8,cc95eb0..4866510
542 --- a/describe.c
543 +++ b/describe.c
544 @@@ -98,20 -98,12 +98,20 @@@
545 return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
546 }
547
548 - static void describe(char *arg)
549 -static void describe(struct commit *cmit, int last_one)
550 ++static void describe(char *arg, int last_one)
551 {
552 + unsigned char sha1[20];
553 + struct commit *cmit;
554 struct commit_list *list;
555 static int initialized = 0;
556 struct commit_name *n;
557
558 + if (get_sha1(arg, sha1) < 0)
559 + usage(describe_usage);
560 + cmit = lookup_commit_reference(sha1);
561 + if (!cmit)
562 + usage(describe_usage);
563 +
564 if (!initialized) {
565 initialized = 1;
566 for_each_ref(get_name);
567
568
569
570 1. It is preceded with a "git diff" header, that looks like this (when
571 -c option is used):
572
573 diff --combined file
574
575 or like this (when --cc option is used):
576
577 diff --cc file
578
579 2. It is followed by one or more extended header lines (this example
580 shows a merge with two parents):
581
582 index <hash>,<hash>..<hash>
583 mode <mode>,<mode>..<mode>
584 new file mode <mode>
585 deleted file mode <mode>,<mode>
586
587 The mode <mode>,<mode>..<mode> line appears only if at least one of
588 the <mode> is different from the rest. Extended headers with
589 information about detected contents movement (renames and copying
590 detection) are designed to work with diff of two <tree-ish> and are
591 not used by combined diff format.
592
593 3. It is followed by two-line from-file/to-file header
594
595 --- a/file
596 +++ b/file
597
598 Similar to two-line header for traditional unified diff format,
599 /dev/null is used to signal created or deleted files.
600
601 4. Chunk header format is modified to prevent people from accidentally
602 feeding it to patch -p1. Combined diff format was created for
603 review of merge commit changes, and was not meant for apply. The
604 change is similar to the change in the extended index header:
605
606 @@@ <from-file-range> <from-file-range> <to-file-range> @@@
607
608 There are (number of parents + 1) @ characters in the chunk header
609 for combined diff format.
610
611 Unlike the traditional unified diff format, which shows two files A and
612 B with a single column that has - (minus — appears in A but removed in
613 B), + (plus — missing in A but added to B), or " " (space — unchanged)
614 prefix, this format compares two or more files file1, file2,... with
615 one file X, and shows how X differs from each of fileN. One column for
616 each of fileN is prepended to the output line to note how X’s line is
617 different from it.
618
619 A - character in the column N means that the line appears in fileN but
620 it does not appear in the result. A + character in the column N means
621 that the line appears in the result, and fileN does not have that line
622 (in other words, the line was added, from the point of view of that
623 parent).
624
625 In the above example output, the function signature was changed from
626 both files (hence two - removals from both file1 and file2, plus ++ to
627 mean one line that was added does not appear in either file1 nor
628 file2). Also eight other lines are the same from file1 but do not
629 appear in file2 (hence prefixed with +).
630
631 When shown by git diff-tree -c, it compares the parents of a merge
632 commit with the merge result (i.e. file1..fileN are the parents). When
633 shown by git diff-files -c, it compares the two unresolved merge
634 parents with the working tree file (i.e. file1 is stage 2 aka "our
635 version", file2 is stage 3 aka "their version").
636
638 The --summary option describes newly added, deleted, renamed and copied
639 files. The --stat option adds diffstat(1) graph to the output. These
640 options can be combined with other options, such as -p, and are meant
641 for human consumption.
642
643 When showing a change that involves a rename or a copy, --stat output
644 formats the pathnames compactly by combining common prefix and suffix
645 of the pathnames. For example, a change that moves arch/i386/Makefile
646 to arch/x86/Makefile while modifying 4 lines will be shown like this:
647
648 arch/{i386 => x86}/Makefile | 4 +--
649
650
651 The --numstat option gives the diffstat(1) information but is designed
652 for easier machine consumption. An entry in --numstat output looks like
653 this:
654
655 1 2 README
656 3 1 arch/{i386 => x86}/Makefile
657
658
659 That is, from left to right:
660
661 1. the number of added lines;
662
663 2. a tab;
664
665 3. the number of deleted lines;
666
667 4. a tab;
668
669 5. pathname (possibly with rename/copy information);
670
671 6. a newline.
672
673 When -z output option is in effect, the output is formatted this way:
674
675 1 2 README NUL
676 3 1 NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
677
678
679 That is:
680
681 1. the number of added lines;
682
683 2. a tab;
684
685 3. the number of deleted lines;
686
687 4. a tab;
688
689 5. a NUL (only exists if renamed/copied);
690
691 6. pathname in preimage;
692
693 7. a NUL (only exists if renamed/copied);
694
695 8. pathname in postimage (only exists if renamed/copied);
696
697 9. a NUL.
698
699 The extra NUL before the preimage path in renamed case is to allow
700 scripts that read the output to tell if the current record being read
701 is a single-path record or a rename/copy record without reading ahead.
702 After reading added and deleted lines, reading up to NUL would yield
703 the pathname, but if that is NUL, the record will show two paths.
704
706 You can choose whether you want to trust the index file entirely (using
707 the --cached flag) or ask the diff logic to show any files that don’t
708 match the stat state as being "tentatively changed". Both of these
709 operations are very useful indeed.
710
712 If --cached is specified, it allows you to ask:
713
714 show me the differences between HEAD and the current index
715 contents (the ones I'd write using 'git write-tree')
716
717 For example, let’s say that you have worked on your working directory,
718 updated some files in the index and are ready to commit. You want to
719 see exactly what you are going to commit, without having to write a new
720 tree object and compare it that way, and to do that, you just do
721
722 git diff-index --cached HEAD
723
724 Example: let’s say I had renamed commit.c to git-commit.c, and I had
725 done an update-index to make that effective in the index file. git
726 diff-files wouldn’t show anything at all, since the index file matches
727 my working directory. But doing a git diff-index does:
728
729 torvalds@ppc970:~/git> git diff-index --cached HEAD
730 -100644 blob 4161aecc6700a2eb579e842af0b7f22b98443f74 commit.c
731 +100644 blob 4161aecc6700a2eb579e842af0b7f22b98443f74 git-commit.c
732
733 You can see easily that the above is a rename.
734
735 In fact, git diff-index --cached should always be entirely equivalent
736 to actually doing a git write-tree and comparing that. Except this one
737 is much nicer for the case where you just want to check where you are.
738
739 So doing a git diff-index --cached is basically very useful when you
740 are asking yourself "what have I already marked for being committed,
741 and what’s the difference to a previous tree".
742
744 The "non-cached" mode takes a different approach, and is potentially
745 the more useful of the two in that what it does can’t be emulated with
746 a git write-tree + git diff-tree. Thus that’s the default mode. The
747 non-cached version asks the question:
748
749 show me the differences between HEAD and the currently checked out
750 tree - index contents _and_ files that aren't up-to-date
751
752 which is obviously a very useful question too, since that tells you
753 what you could commit. Again, the output matches the git diff-tree -r
754 output to a tee, but with a twist.
755
756 The twist is that if some file doesn’t match the index, we don’t have a
757 backing store thing for it, and we use the magic "all-zero" sha1 to
758 show that. So let’s say that you have edited kernel/sched.c, but have
759 not actually done a git update-index on it yet - there is no "object"
760 associated with the new state, and you get:
761
762 torvalds@ppc970:~/v2.6/linux> git diff-index HEAD
763 *100644->100664 blob 7476bb......->000000...... kernel/sched.c
764
765 i.e., it shows that the tree has changed, and that kernel/sched.c has
766 is not up-to-date and may contain new stuff. The all-zero sha1 means
767 that to get the real diff, you need to look at the object in the
768 working directory directly rather than do an object-to-object diff.
769
770 Note
771 As with other commands of this type, git diff-index does not
772 actually look at the contents of the file at all. So maybe
773 kernel/sched.c hasn’t actually changed, and it’s just that you
774 touched it. In either case, it’s a note that you need to git
775 update-index it to make the index be in sync.
776
777 Note
778 You can have a mixture of files show up as "has been updated" and
779 "is still dirty in the working directory" together. You can always
780 tell which file is in which state, since the "has been updated"
781 ones show a valid sha1, and the "not in sync with the index" ones
782 will always have the special all-zero sha1.
783
785 Written by Linus Torvalds <torvalds@osdl.org[1]>
786
788 Documentation by David Greaves, Junio C Hamano and the git-list
789 <git@vger.kernel.org[2]>.
790
792 Part of the git(1) suite
793
795 1. torvalds@osdl.org
796 mailto:torvalds@osdl.org
797
798 2. git@vger.kernel.org
799 mailto:git@vger.kernel.org
800
801
802
803Git 1.7.4.4 04/11/2011 GIT-DIFF-INDEX(1)