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.4.5" />
7 <title>git-diff-index(
1)
</title>
8 <style type=
"text/css">
10 p
, li
, dt
, dd
, div
, pre
, h1
, h2
, h3
, h4
, h5
, h6
{
12 border: 1px solid red;
17 margin: 1em 5% 1em 5%;
22 text-decoration: underline
;
42 h1
, h2
, h3
, h4
, h5
, h6
{
44 font-family: sans-serif
;
51 border-bottom: 2px solid silver
;
69 border: 1px solid silver
;
88 font-family: sans-serif
;
94 span#revnumber
, span#revdate
, span#revremark
{
95 font-family: sans-serif
;
99 font-family: sans-serif
;
101 border-top: 2px solid silver
;
107 padding-bottom: 0.5em;
111 padding-bottom: 0.5em;
116 margin-bottom: 1.5em;
118 div
.tableblock
, div
.imageblock
, div
.exampleblock
, div
.verseblock
,
119 div
.quoteblock
, div
.literalblock
, div
.listingblock
, div
.sidebarblock
,
120 div
.admonitionblock
{
122 margin-bottom: 1.5em;
124 div
.admonitionblock
{
126 margin-bottom: 2.5em;
129 div
.content
{ /* Block element content. */
133 /* Block element titles. */
134 div
.title
, caption
.title
{
136 font-family: sans-serif
;
140 margin-bottom: 0.5em;
146 td div
.title:first-child
{
149 div
.content div
.title:first-child
{
152 div
.content
+ div
.title
{
156 div
.sidebarblock
> div
.content
{
158 border: 1px solid silver
;
162 div
.listingblock
> div
.content
{
163 border: 1px solid silver
;
172 div
.quoteblock
> div
.attribution
{
181 div
.verseblock
> div
.content
{
184 div
.verseblock
> div
.attribution
{
188 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
189 div
.verseblock
+ div
.attribution
{
193 div
.admonitionblock
.icon
{
197 text-decoration: underline
;
199 padding-right: 0.5em;
201 div
.admonitionblock td
.content
{
203 border-left: 2px solid silver
;
206 div
.exampleblock
> div
.content
{
207 border-left: 2px solid silver
;
211 div
.imageblock div
.content
{ padding-left: 0; }
212 span
.image img
{ border-style: none
; }
213 a
.image:visited
{ color: white
; }
217 margin-bottom: 0.8em;
230 list-style-position: outside
;
233 list-style-type: decimal
;
236 list-style-type: lower-alpha
;
239 list-style-type: upper-alpha
;
242 list-style-type: lower-roman
;
245 list-style-type: upper-roman
;
248 div
.compact ul
, div
.compact ol
,
249 div
.compact p
, div
.compact p
,
250 div
.compact div
, div
.compact div
{
252 margin-bottom: 0.1em;
255 div
.tableblock
> table
{
256 border: 3px solid
#527bbd;
259 font-family: sans-serif
;
271 /* Because the table frame attribute is overriden by CSS in most browsers. */
272 div
.tableblock
> table
[frame
="void"] {
275 div
.tableblock
> table
[frame
="hsides"] {
276 border-left-style: none
;
277 border-right-style: none
;
279 div
.tableblock
> table
[frame
="vsides"] {
280 border-top-style: none
;
281 border-bottom-style: none
;
287 margin-bottom: 0.8em;
290 padding-bottom: 15px;
292 dt
.hdlist1
.strong
, td
.hdlist1
.strong
{
298 padding-right: 0.8em;
304 div
.hdlist
.compact tr
{
314 div#footer-badges
{ display: none
; }
319 font-family: sans-serif
;
323 margin-bottom: 0.1em;
326 div
.toclevel1
, div
.toclevel2
, div
.toclevel3
, div
.toclevel4
{
342 /* Overrides for manpage documents */
345 padding-bottom: 0.5em;
346 border-top: 2px solid silver
;
347 border-bottom: 2px solid silver
;
357 div#toc
{ display: none
; }
360 /* Workarounds for IE6's broken and incomplete CSS2. */
362 div
.sidebar-content
{
364 border: 1px solid silver
;
367 div
.sidebar-title
, div
.image-title
{
369 font-family: sans-serif
;
372 margin-bottom: 0.5em;
375 div
.listingblock div
.content
{
376 border: 1px solid silver
;
381 div
.quoteblock-attribution
{
386 div
.verseblock-content
{
389 div
.verseblock-attribution
{
394 div
.exampleblock-content
{
395 border-left: 2px solid silver
;
399 /* IE6 sets dynamically generated links as visited. */
400 div#toc
a:visited
{ color: blue
; }
406 git-diff-index(
1) Manual Page
409 <div class=
"sectionbody">
411 Compares content and mode of blobs between the index and repository
415 <h2 id=
"_synopsis">SYNOPSIS
</h2>
416 <div class=
"sectionbody">
417 <div class=
"paragraph"><p><em>git diff-index
</em> [-m] [--cached] [
<common diff options
>]
<tree-ish
> [
<path
>…]
</p></div>
419 <h2 id=
"_description">DESCRIPTION
</h2>
420 <div class=
"sectionbody">
421 <div class=
"paragraph"><p>Compares the content and mode of the blobs found via a tree
422 object with the content of the current index and, optionally
423 ignoring the stat state of the file on disk. When paths are
424 specified, compares only those named paths. Otherwise all
425 entries in the index are compared.
</p></div>
427 <h2 id=
"_options">OPTIONS
</h2>
428 <div class=
"sectionbody">
429 <div class=
"dlist"><dl>
441 Generate patch (see section on generating patches).
453 Generate diffs with
<n
> lines of context instead of
463 Generate the raw format.
472 Synonym for
<tt>-p --raw
</tt>.
480 Generate a diff using the
"patience diff" algorithm.
484 --stat[=
<width
>[,
<name-width
>]]
488 Generate a diffstat. You can override the default
489 output width for
80-column terminal by
<tt>--stat=
<width
></tt>.
490 The width of the filename part can be controlled by
491 giving another width to it separated by a comma.
499 Similar to
<tt>--stat
</tt>, but shows number of added and
500 deleted lines in decimal notation and pathname without
501 abbreviation, to make it more machine friendly. For
502 binary files, outputs two
<tt>-
</tt> instead of saying
511 Output only the last line of the
<tt>--stat
</tt> format containing total
512 number of modified files, as well as number of added and deleted
517 --dirstat[=
<param1,param2,
…>]
521 Output the distribution of relative amount of changes for each
522 sub-directory. The behavior of
<tt>--dirstat
</tt> can be customized by
523 passing it a comma separated list of parameters.
524 The defaults are controlled by the
<tt>diff.dirstat
</tt> configuration
525 variable (see
<a href=
"git-config.html">git-config(
1)
</a>).
526 The following parameters are available:
528 <div class=
"dlist"><dl>
534 Compute the dirstat numbers by counting the lines that have been
535 removed from the source, or added to the destination. This ignores
536 the amount of pure code movements within a file. In other words,
537 rearranging lines in a file is not counted as much as other changes.
538 This is the default behavior when no parameter is given.
546 Compute the dirstat numbers by doing the regular line-based diff
547 analysis, and summing the removed/added line counts. (For binary
548 files, count
64-byte chunks instead, since binary files have no
549 natural concept of lines). This is a more expensive
<tt>--dirstat
</tt>
550 behavior than the
<tt>changes
</tt> behavior, but it does count rearranged
551 lines within a file as much as other changes. The resulting output
552 is consistent with what you get from the other
<tt>--*stat
</tt> options.
560 Compute the dirstat numbers by counting the number of files changed.
561 Each changed file counts equally in the dirstat analysis. This is
562 the computationally cheapest
<tt>--dirstat
</tt> behavior, since it does
563 not have to look at the file contents at all.
571 Count changes in a child directory for the parent directory as well.
572 Note that when using
<tt>cumulative
</tt>, the sum of the percentages
573 reported may exceed
100%. The default (non-cumulative) behavior can
574 be specified with the
<tt>noncumulative
</tt> parameter.
582 An integer parameter specifies a cut-off percent (
3% by default).
583 Directories contributing less than this percentage of the changes
584 are not shown in the output.
588 <div class=
"paragraph"><p>Example: The following will count changed files, while ignoring
589 directories with less than
10% of the total amount of changed files,
590 and accumulating child directory counts in the parent directories:
591 <tt>--dirstat=files,
10,cumulative
</tt>.
</p></div>
598 Output a condensed summary of extended header information
599 such as creations, renames and mode changes.
607 Synonym for
<tt>-p --stat
</tt>.
615 When
<tt>--raw
</tt>,
<tt>--numstat
</tt>,
<tt>--name-only
</tt> or
<tt>--name-status
</tt> has been
616 given, do not munge pathnames and use NULs as output field terminators.
618 <div class=
"paragraph"><p>Without this option, each pathname output will have TAB, LF, double quotes,
619 and backslash characters replaced with
<tt>\t
</tt>,
<tt>\n
</tt>,
<tt>\
"</tt>, and <tt>\\</tt>,
620 respectively, and the pathname will be enclosed in double quotes if
621 any of those replacements occurred.</p></div>
628 Show only names of changed files.
636 Show only names and status of changed files. See the description
637 of the <tt>--diff-filter</tt> option on what the status letters mean.
641 --submodule[=<format>]
645 Chose the output format for submodule differences. <format> can be one of
646 <em>short</em> and <em>log</em>. <em>short</em> just shows pairs of commit names, this format
647 is used when this option is not given. <em>log</em> is the default value for this
648 option and lists the commits in that commit range like the <em>summary</em>
649 option of <a href="git-submodule.html
">git-submodule(1)</a> does.
653 --color[=<when>]
658 The value must be <tt>always</tt> (the default for <tt><when></tt>), <tt>never</tt>, or <tt>auto</tt>.
659 The default value is <tt>never</tt>.
667 Turn off colored diff.
668 It is the same as <tt>--color=never</tt>.
672 --word-diff[=<mode>]
676 Show a word diff, using the <mode> to delimit changed words.
677 By default, words are delimited by whitespace; see
678 <tt>--word-diff-regex</tt> below. The <mode> defaults to <em>plain</em>, and
681 <div class="dlist
"><dl>
687 Highlight changed words using only colors. Implies <tt>--color</tt>.
695 Show words as <tt>[-removed-]</tt> and <tt>{<tt>added</tt>}</tt>. Makes no
696 attempts to escape the delimiters if they appear in the input,
697 so the output may be ambiguous.
705 Use a special line-based format intended for script
706 consumption. Added/removed/unchanged runs are printed in the
707 usual unified diff format, starting with a <tt>+</tt>/<tt>-</tt>/` `
708 character at the beginning of the line and extending to the
709 end of the line. Newlines in the input are represented by a
710 tilde <tt>~</tt> on a line of its own.
718 Disable word diff again.
722 <div class="paragraph
"><p>Note that despite the name of the first mode, color is used to
723 highlight the changed parts in all modes if enabled.</p></div>
726 --word-diff-regex=<regex>
730 Use <regex> to decide what a word is, instead of considering
731 runs of non-whitespace to be a word. Also implies
732 <tt>--word-diff</tt> unless it was already enabled.
734 <div class="paragraph
"><p>Every non-overlapping match of the
735 <regex> is considered a word. Anything between these matches is
736 considered whitespace and ignored(!) for the purposes of finding
737 differences. You may want to append <tt>|[^[:space:]]</tt> to your regular
738 expression to make sure that it matches all non-whitespace characters.
739 A match that contains a newline is silently truncated(!) at the
741 <div class="paragraph
"><p>The regex can also be set via a diff driver or configuration option, see
742 <a href="gitattributes.html
">gitattributes(1)</a> or <a href="git-config.html
">git-config(1)</a>. Giving it explicitly
743 overrides any diff driver or configuration setting. Diff drivers
744 override configuration settings.</p></div>
747 --color-words[=<regex>]
751 Equivalent to <tt>--word-diff=color</tt> plus (if a regex was
752 specified) <tt>--word-diff-regex=<regex></tt>.
760 Turn off rename detection, even when the configuration
761 file gives the default to do so.
769 Warn if changes introduce trailing whitespace
770 or an indent that uses a space before a tab. Exits with
771 non-zero status if problems are found. Not compatible with
780 Instead of the first handful of characters, show the full
781 pre- and post-image blob object names on the "index
"
782 line when generating patch format output.
790 In addition to <tt>--full-index</tt>, output a binary diff that
791 can be applied with <tt>git-apply</tt>.
799 Instead of showing the full 40-byte hexadecimal object
800 name in diff-raw format output and diff-tree header
801 lines, show only a partial prefix. This is
802 independent of the <tt>--full-index</tt> option above, which controls
803 the diff-patch output format. Non default number of
804 digits can be specified with <tt>--abbrev=<n></tt>.
808 -B[<n>][/<m>]
811 --break-rewrites[=[<n>][/<m>]]
815 Break complete rewrite changes into pairs of delete and
816 create. This serves two purposes:
818 <div class="paragraph
"><p>It affects the way a change that amounts to a total rewrite of a file
819 not as a series of deletion and insertion mixed together with a very
820 few lines that happen to match textually as the context, but as a
821 single deletion of everything old followed by a single insertion of
822 everything new, and the number <tt>m</tt> controls this aspect of the -B
823 option (defaults to 60%). <tt>-B/70%</tt> specifies that less than 30% of the
824 original should remain in the result for git to consider it a total
825 rewrite (i.e. otherwise the resulting patch will be a series of
826 deletion and insertion mixed together with context lines).</p></div>
827 <div class="paragraph
"><p>When used with -M, a totally-rewritten file is also considered as the
828 source of a rename (usually -M only considers a file that disappeared
829 as the source of a rename), and the number <tt>n</tt> controls this aspect of
830 the -B option (defaults to 50%). <tt>-B20%</tt> specifies that a change with
831 addition and deletion compared to 20% or more of the file’s size are
832 eligible for being picked up as a possible source of a rename to
833 another file.</p></div>
839 --find-renames[=<n>]
844 If <tt>n</tt> is specified, it is a threshold on the similarity
845 index (i.e. amount of addition/deletions compared to the
846 file’s size). For example, <tt>-M90%</tt> means git should consider a
847 delete/add pair to be a rename if more than 90% of the file
848 hasn’t changed.
855 --find-copies[=<n>]
859 Detect copies as well as renames. See also <tt>--find-copies-harder</tt>.
860 If <tt>n</tt> is specified, it has the same meaning as for <tt>-M<n></tt>.
868 For performance reasons, by default, <tt>-C</tt> option finds copies only
869 if the original file of the copy was modified in the same
870 changeset. This flag makes the command
871 inspect unmodified files as candidates for the source of
872 copy. This is a very expensive operation for large
873 projects, so use it with caution. Giving more than one
874 <tt>-C</tt> option has the same effect.
881 --irreversible-delete
885 Omit the preimage for deletes, i.e. print only the header but not
886 the diff between the preimage and <tt>/dev/null</tt>. The resulting patch
887 is not meant to be applied with <tt>patch</tt> nor <tt>git apply</tt>; this is
888 solely for people who want to just concentrate on reviewing the
889 text after the change. In addition, the output obviously lack
890 enough information to apply such a patch in reverse, even manually,
891 hence the name of the option.
893 <div class="paragraph
"><p>When used together with <tt>-B</tt>, omit also the preimage in the deletion part
894 of a delete/create pair.</p></div>
901 The <tt>-M</tt> and <tt>-C</tt> options require O(n^2) processing time where n
902 is the number of potential rename/copy targets. This
903 option prevents rename/copy detection from running if
904 the number of rename/copy targets exceeds the specified
909 --diff-filter=[(A|C|D|M|R|T|U|X|B)…[*]]
913 Select only files that are Added (<tt>A</tt>), Copied (<tt>C</tt>),
914 Deleted (<tt>D</tt>), Modified (<tt>M</tt>), Renamed (<tt>R</tt>), have their
915 type (i.e. regular file, symlink, submodule, …) changed (<tt>T</tt>),
916 are Unmerged (<tt>U</tt>), are
917 Unknown (<tt>X</tt>), or have had their pairing Broken (<tt>B</tt>).
918 Any combination of the filter characters (including none) can be used.
919 When <tt>*</tt> (All-or-none) is added to the combination, all
920 paths are selected if there is any file that matches
921 other criteria in the comparison; if there is no file
922 that matches other criteria, nothing is selected.
930 Look for differences that introduce or remove an instance of
931 <string>. Note that this is different than the string simply
932 appearing in diff output; see the <em>pickaxe</em> entry in
933 <a href="gitdiffcore.html
">gitdiffcore(7)</a> for more details.
941 Look for differences whose added or removed line matches
942 the given <regex>.
950 When <tt>-S</tt> or <tt>-G</tt> finds a change, show all the changes in that
951 changeset, not just the files that contain the change
960 Make the <string> not a plain string but an extended POSIX
969 Output the patch in the order specified in the
970 <orderfile>, which has one shell glob pattern per line.
978 Swap two inputs; that is, show differences from index or
979 on-disk file to tree contents.
983 --relative[=<path>]
987 When run from a subdirectory of the project, it can be
988 told to exclude changes outside the directory and show
989 pathnames relative to it with this option. When you are
990 not in a subdirectory (e.g. in a bare repository), you
991 can name which subdirectory to make the output relative
992 to by giving a <path> as an argument.
1003 Treat all files as text.
1006 <dt class="hdlist1
">
1007 --ignore-space-at-eol
1011 Ignore changes in whitespace at EOL.
1014 <dt class="hdlist1
">
1017 <dt class="hdlist1
">
1018 --ignore-space-change
1022 Ignore changes in amount of whitespace. This ignores whitespace
1023 at line end, and considers all other sequences of one or
1024 more whitespace characters to be equivalent.
1027 <dt class="hdlist1
">
1030 <dt class="hdlist1
">
1035 Ignore whitespace when comparing lines. This ignores
1036 differences even if one line has whitespace where the other
1040 <dt class="hdlist1
">
1041 --inter-hunk-context=<lines>
1045 Show the context between diff hunks, up to the specified number
1046 of lines, thereby fusing hunks that are close to each other.
1049 <dt class="hdlist1
">
1054 Make the program exit with codes similar to diff(1).
1055 That is, it exits with 1 if there were differences and
1056 0 means no differences.
1059 <dt class="hdlist1
">
1064 Disable all output of the program. Implies <tt>--exit-code</tt>.
1067 <dt class="hdlist1
">
1072 Allow an external diff helper to be executed. If you set an
1073 external diff driver with <a href="gitattributes.html
">gitattributes(5)</a>, you need
1074 to use this option with <a href="git-log.html
">git-log(1)</a> and friends.
1077 <dt class="hdlist1
">
1082 Disallow external diff drivers.
1085 <dt class="hdlist1
">
1086 --ignore-submodules[=<when>]
1090 Ignore changes to submodules in the diff generation. <when> can be
1091 either "none
", "untracked
", "dirty
" or "all
", which is the default
1092 Using "none
" will consider the submodule modified when it either contains
1093 untracked or modified files or its HEAD differs from the commit recorded
1094 in the superproject and can be used to override any settings of the
1095 <em>ignore</em> option in <a href="git-config.html
">git-config(1)</a> or <a href="gitmodules.html
">gitmodules(5)</a>. When
1096 "untracked
" is used submodules are not considered dirty when they only
1097 contain untracked content (but they are still scanned for modified
1098 content). Using "dirty
" ignores all changes to the work tree of submodules,
1099 only changes to the commits stored in the superproject are shown (this was
1100 the behavior until 1.7.0). Using "all
" hides all changes to submodules.
1103 <dt class="hdlist1
">
1104 --src-prefix=<prefix>
1108 Show the given source prefix instead of "a/
".
1111 <dt class="hdlist1
">
1112 --dst-prefix=<prefix>
1116 Show the given destination prefix instead of "b/
".
1119 <dt class="hdlist1
">
1124 Do not show any source or destination prefix.
1128 <div class="paragraph
"><p>For more detailed explanation on these common options, see also
1129 <a href="gitdiffcore.html
">gitdiffcore(7)</a>.</p></div>
1130 <div class="dlist
"><dl>
1131 <dt class="hdlist1
">
1136 The id of a tree object to diff against.
1139 <dt class="hdlist1
">
1144 do not consider the on-disk file at all
1147 <dt class="hdlist1
">
1152 By default, files recorded in the index but not checked
1153 out are reported as deleted. This flag makes
1154 <em>git diff-index</em> say that all non-checked-out files are up
1160 <h2 id="_raw_output_format
">Raw output format</h2>
1161 <div class="sectionbody
">
1162 <div class="paragraph
"><p>The raw output format from "git-diff-index
", "git-diff-tree
",
1163 "git-diff-files
" and "git diff --raw
" are very similar.</p></div>
1164 <div class="paragraph
"><p>These commands all compare two sets of things; what is
1165 compared differs:</p></div>
1166 <div class="dlist
"><dl>
1167 <dt class="hdlist1
">
1168 git-diff-index <tree-ish>
1172 compares the <tree-ish> and the files on the filesystem.
1175 <dt class="hdlist1
">
1176 git-diff-index --cached <tree-ish>
1180 compares the <tree-ish> and the index.
1183 <dt class="hdlist1
">
1184 git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>…]
1188 compares the trees named by the two arguments.
1191 <dt class="hdlist1
">
1192 git-diff-files [<pattern>…]
1196 compares the index and the files on the filesystem.
1200 <div class="paragraph
"><p>The "git-diff-tree
" command begins its output by printing the hash of
1201 what is being compared. After that, all the commands print one output
1202 line per changed file.</p></div>
1203 <div class="paragraph
"><p>An output line is formatted this way:</p></div>
1204 <div class="listingblock
">
1205 <div class="content
">
1206 <pre><tt>in-place edit :100644 100644 bcd1234... 0123456... M file0
1207 copy-edit :100644 100644 abcd123... 1234567... C68 file1 file2
1208 rename-edit :100644 100644 abcd123... 1234567... R86 file1 file3
1209 create :000000 100644 0000000... 1234567... A file4
1210 delete :100644 000000 1234567... 0000000... D file5
1211 unmerged :000000 000000 0000000... 0000000... U file6</tt></pre>
1213 <div class="paragraph
"><p>That is, from the left to the right:</p></div>
1214 <div class="olist arabic
"><ol class="arabic
">
1222 mode for "src
"; 000000 if creation or unmerged.
1232 mode for "dst
"; 000000 if deletion or unmerged.
1242 sha1 for "src
"; 0{40} if creation or unmerged.
1252 sha1 for "dst
"; 0{40} if creation, unmerged or "look at work tree
".
1262 status, followed by optional "score
" number.
1267 a tab or a NUL when <em>-z</em> option is used.
1277 a tab or a NUL when <em>-z</em> option is used; only exists for C or R.
1282 path for "dst
"; only exists for C or R.
1287 an LF or a NUL when <em>-z</em> option is used, to terminate the record.
1291 <div class="paragraph
"><p>Possible status letters are:</p></div>
1292 <div class="ulist
"><ul>
1295 A: addition of a file
1300 C: copy of a file into a new one
1305 D: deletion of a file
1310 M: modification of the contents or mode of a file
1315 R: renaming of a file
1320 T: change in the type of the file
1325 U: file is unmerged (you must complete the merge before it can
1331 X: "unknown
" change type (most probably a bug, please report it)
1335 <div class="paragraph
"><p>Status letters C and R are always followed by a score (denoting the
1336 percentage of similarity between the source and target of the move or
1337 copy), and are the only ones to be so.</p></div>
1338 <div class="paragraph
"><p><sha1> is shown as all 0’s if a file is new on the filesystem
1339 and it is out of sync with the index.</p></div>
1340 <div class="paragraph
"><p>Example:</p></div>
1341 <div class="listingblock
">
1342 <div class="content
">
1343 <pre><tt>:100644 100644 5be4a4...... 000000...... M file.c</tt></pre>
1345 <div class="paragraph
"><p>When <tt>-z</tt> option is not used, TAB, LF, and backslash characters
1346 in pathnames are represented as <tt>\t</tt>, <tt>\n</tt>, and <tt>\\</tt>,
1347 respectively.</p></div>
1349 <h2 id="_diff_format_for_merges
">diff format for merges</h2>
1350 <div class="sectionbody
">
1351 <div class="paragraph
"><p>"git-diff-tree
", "git-diff-files
" and "git-diff --raw
"
1352 can take <em>-c</em> or <em>--cc</em> option
1353 to generate diff output also for merge commits. The output differs
1354 from the format described above in the following way:</p></div>
1355 <div class="olist arabic
"><ol class="arabic
">
1358 there is a colon for each parent
1363 there are more "src
" modes and "src
" sha1
1368 status is concatenated status characters for each parent
1373 no optional "score
" number
1378 single path, only for "dst
"
1382 <div class="paragraph
"><p>Example:</p></div>
1383 <div class="listingblock
">
1384 <div class="content
">
1385 <pre><tt>::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM describe.c</tt></pre>
1387 <div class="paragraph
"><p>Note that <em>combined diff</em> lists only files which were modified from
1388 all parents.</p></div>
1390 <h2 id="_generating_patches_with_p
">Generating patches with -p</h2>
1391 <div class="sectionbody
">
1392 <div class="paragraph
"><p>When "git-diff-index
", "git-diff-tree
", or "git-diff-files
" are run
1393 with a <em>-p</em> option, "git diff
" without the <em>--raw</em> option, or
1394 "git log
" with the "-p
" option, they
1395 do not produce the output described above; instead they produce a
1396 patch file. You can customize the creation of such patches via the
1397 GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables.</p></div>
1398 <div class="paragraph
"><p>What the -p option produces is slightly different from the traditional
1399 diff format:</p></div>
1400 <div class="olist arabic
"><ol class="arabic
">
1403 It is preceded with a "git diff
" header that looks like this:
1405 <div class="literalblock
">
1406 <div class="content
">
1407 <pre><tt>diff --git a/file1 b/file2</tt></pre>
1409 <div class="paragraph
"><p>The <tt>a/</tt> and <tt>b/</tt> filenames are the same unless rename/copy is
1410 involved. Especially, even for a creation or a deletion,
1411 <tt>/dev/null</tt> is <em>not</em> used in place of the <tt>a/</tt> or <tt>b/</tt> filenames.</p></div>
1412 <div class="paragraph
"><p>When rename/copy is involved, <tt>file1</tt> and <tt>file2</tt> show the
1413 name of the source file of the rename/copy and the name of
1414 the file that rename/copy produces, respectively.</p></div>
1418 It is followed by one or more extended header lines:
1420 <div class="literalblock
">
1421 <div class="content
">
1422 <pre><tt>old mode <mode>
1423 new mode <mode>
1424 deleted file mode <mode>
1425 new file mode <mode>
1426 copy from <path>
1427 copy to <path>
1428 rename from <path>
1429 rename to <path>
1430 similarity index <number>
1431 dissimilarity index <number>
1432 index <hash>..<hash> <mode></tt></pre>
1434 <div class="paragraph
"><p>File modes are printed as 6-digit octal numbers including the file type
1435 and file permission bits.</p></div>
1436 <div class="paragraph
"><p>Path names in extended headers do not include the <tt>a/</tt> and <tt>b/</tt> prefixes.</p></div>
1437 <div class="paragraph
"><p>The similarity index is the percentage of unchanged lines, and
1438 the dissimilarity index is the percentage of changed lines. It
1439 is a rounded down integer, followed by a percent sign. The
1440 similarity index value of 100% is thus reserved for two equal
1441 files, while 100% dissimilarity means that no line from the old
1442 file made it into the new one.</p></div>
1443 <div class="paragraph
"><p>The index line includes the SHA-1 checksum before and after the change.
1444 The <mode> is included if the file mode does not change; otherwise,
1445 separate lines indicate the old and the new mode.</p></div>
1449 TAB, LF, double quote and backslash characters in pathnames
1450 are represented as <tt>\t</tt>, <tt>\n</tt>, <tt>\"</tt> and
<tt>\\
</tt>, respectively.
1451 If there is need for such substitution then the whole
1452 pathname is put in double quotes.
1457 All the
<tt>file1
</tt> files in the output refer to files before the
1458 commit, and all the
<tt>file2
</tt> files refer to files after the commit.
1459 It is incorrect to apply each change to each file sequentially. For
1460 example, this patch will swap a and b:
1462 <div class=
"literalblock">
1463 <div class=
"content">
1464 <pre><tt>diff --git a/a b/b
1469 rename to a
</tt></pre>
1474 <h2 id=
"_combined_diff_format">combined diff format
</h2>
1475 <div class=
"sectionbody">
1476 <div class=
"paragraph"><p>Any diff-generating command can take the
‘-c` or
<tt>--cc
</tt> option to
1477 produce a
<em>combined diff
</em> when showing a merge. This is the default
1478 format when showing merges with
<a href=
"git-diff.html">git-diff(
1)
</a> or
1479 <a href=
"git-show.html">git-show(
1)
</a>. Note also that you can give the `-m
’ option to any
1480 of these commands to force generation of diffs with individual parents
1481 of a merge.
</p></div>
1482 <div class=
"paragraph"><p>A
<em>combined diff
</em> format looks like this:
</p></div>
1483 <div class=
"listingblock">
1484 <div class=
"content">
1485 <pre><tt>diff --combined describe.c
1486 index fabadb8,cc95eb0.
.4866510
1489 @@@ -
98,
20 -
98,
12 +
98,
20 @@@
1490 return (a_date
> b_date) ? -
1 : (a_date == b_date) ?
0 :
1;
1493 - static void describe(char *arg)
1494 -static void describe(struct commit *cmit, int last_one)
1495 ++static void describe(char *arg, int last_one)
1497 + unsigned char sha1[
20];
1498 + struct commit *cmit;
1499 struct commit_list *list;
1500 static int initialized =
0;
1501 struct commit_name *n;
1503 + if (get_sha1(arg, sha1)
< 0)
1504 + usage(describe_usage);
1505 + cmit = lookup_commit_reference(sha1);
1507 + usage(describe_usage);
1511 for_each_ref(get_name);
</tt></pre>
1513 <div class=
"olist arabic"><ol class=
"arabic">
1516 It is preceded with a
"git diff" header, that looks like
1517 this (when
<em>-c
</em> option is used):
1519 <div class=
"literalblock">
1520 <div class=
"content">
1521 <pre><tt>diff --combined file
</tt></pre>
1523 <div class=
"paragraph"><p>or like this (when
<em>--cc
</em> option is used):
</p></div>
1524 <div class=
"literalblock">
1525 <div class=
"content">
1526 <pre><tt>diff --cc file
</tt></pre>
1531 It is followed by one or more extended header lines
1532 (this example shows a merge with two parents):
1534 <div class=
"literalblock">
1535 <div class=
"content">
1536 <pre><tt>index
<hash
>,
<hash
>..
<hash
>
1537 mode
<mode
>,
<mode
>..
<mode
>
1538 new file mode
<mode
>
1539 deleted file mode
<mode
>,
<mode
></tt></pre>
1541 <div class=
"paragraph"><p>The
<tt>mode
<mode
>,
<mode
>..
<mode
></tt> line appears only if at least one of
1542 the
<mode
> is different from the rest. Extended headers with
1543 information about detected contents movement (renames and
1544 copying detection) are designed to work with diff of two
1545 <tree-ish
> and are not used by combined diff format.
</p></div>
1549 It is followed by two-line from-file/to-file header
1551 <div class=
"literalblock">
1552 <div class=
"content">
1554 +++ b/file
</tt></pre>
1556 <div class=
"paragraph"><p>Similar to two-line header for traditional
<em>unified
</em> diff
1557 format,
<tt>/dev/null
</tt> is used to signal created or deleted
1562 Chunk header format is modified to prevent people from
1563 accidentally feeding it to
<tt>patch -p1
</tt>. Combined diff format
1564 was created for review of merge commit changes, and was not
1565 meant for apply. The change is similar to the change in the
1566 extended
<em>index
</em> header:
1568 <div class=
"literalblock">
1569 <div class=
"content">
1570 <pre><tt>@@@
<from-file-range
> <from-file-range
> <to-file-range
> @@@
</tt></pre>
1572 <div class=
"paragraph"><p>There are (number of parents +
1)
<tt>@
</tt> characters in the chunk
1573 header for combined diff format.
</p></div>
1576 <div class=
"paragraph"><p>Unlike the traditional
<em>unified
</em> diff format, which shows two
1577 files A and B with a single column that has
<tt>-
</tt> (minus
 — appears in A but removed in B),
<tt>+
</tt> (plus
 — missing in A but
1578 added to B), or
<tt>" "</tt> (space
 — unchanged) prefix, this format
1579 compares two or more files file1, file2,
… with one file X, and
1580 shows how X differs from each of fileN. One column for each of
1581 fileN is prepended to the output line to note how X
’s line is
1582 different from it.
</p></div>
1583 <div class=
"paragraph"><p>A
<tt>-
</tt> character in the column N means that the line appears in
1584 fileN but it does not appear in the result. A
<tt>+
</tt> character
1585 in the column N means that the line appears in the result,
1586 and fileN does not have that line (in other words, the line was
1587 added, from the point of view of that parent).
</p></div>
1588 <div class=
"paragraph"><p>In the above example output, the function signature was changed
1589 from both files (hence two
<tt>-
</tt> removals from both file1 and
1590 file2, plus
<tt>++
</tt> to mean one line that was added does not appear
1591 in either file1 nor file2). Also eight other lines are the same
1592 from file1 but do not appear in file2 (hence prefixed with
<tt>+</tt>).
</p></div>
1593 <div class=
"paragraph"><p>When shown by
<tt>git diff-tree -c
</tt>, it compares the parents of a
1594 merge commit with the merge result (i.e. file1..fileN are the
1595 parents). When shown by
<tt>git diff-files -c
</tt>, it compares the
1596 two unresolved merge parents with the working tree file
1597 (i.e. file1 is stage
2 aka
"our version", file2 is stage
3 aka
1598 "their version").
</p></div>
1600 <h2 id=
"_other_diff_formats">other diff formats
</h2>
1601 <div class=
"sectionbody">
1602 <div class=
"paragraph"><p>The
<tt>--summary
</tt> option describes newly added, deleted, renamed and
1603 copied files. The
<tt>--stat
</tt> option adds diffstat(
1) graph to the
1604 output. These options can be combined with other options, such as
1605 <tt>-p
</tt>, and are meant for human consumption.
</p></div>
1606 <div class=
"paragraph"><p>When showing a change that involves a rename or a copy,
<tt>--stat
</tt> output
1607 formats the pathnames compactly by combining common prefix and suffix of
1608 the pathnames. For example, a change that moves
<tt>arch/i386/Makefile
</tt> to
1609 <tt>arch/x86/Makefile
</tt> while modifying
4 lines will be shown like this:
</p></div>
1610 <div class=
"listingblock">
1611 <div class=
"content">
1612 <pre><tt>arch/{i386 =
> x86}/Makefile |
4 +--
</tt></pre>
1614 <div class=
"paragraph"><p>The
<tt>--numstat
</tt> option gives the diffstat(
1) information but is designed
1615 for easier machine consumption. An entry in
<tt>--numstat
</tt> output looks
1616 like this:
</p></div>
1617 <div class=
"listingblock">
1618 <div class=
"content">
1620 3 1 arch/{i386 =
> x86}/Makefile
</tt></pre>
1622 <div class=
"paragraph"><p>That is, from left to right:
</p></div>
1623 <div class=
"olist arabic"><ol class=
"arabic">
1626 the number of added lines;
1636 the number of deleted lines;
1646 pathname (possibly with rename/copy information);
1655 <div class=
"paragraph"><p>When
<tt>-z
</tt> output option is in effect, the output is formatted this way:
</p></div>
1656 <div class=
"listingblock">
1657 <div class=
"content">
1658 <pre><tt>1 2 README NUL
1659 3 1 NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
</tt></pre>
1661 <div class=
"paragraph"><p>That is:
</p></div>
1662 <div class=
"olist arabic"><ol class=
"arabic">
1665 the number of added lines;
1675 the number of deleted lines;
1685 a NUL (only exists if renamed/copied);
1690 pathname in preimage;
1695 a NUL (only exists if renamed/copied);
1700 pathname in postimage (only exists if renamed/copied);
1709 <div class=
"paragraph"><p>The extra
<tt>NUL
</tt> before the preimage path in renamed case is to allow
1710 scripts that read the output to tell if the current record being read is
1711 a single-path record or a rename/copy record without reading ahead.
1712 After reading added and deleted lines, reading up to
<tt>NUL
</tt> would yield
1713 the pathname, but if that is
<tt>NUL
</tt>, the record will show two paths.
</p></div>
1715 <h2 id=
"_operating_modes">Operating Modes
</h2>
1716 <div class=
"sectionbody">
1717 <div class=
"paragraph"><p>You can choose whether you want to trust the index file entirely
1718 (using the
<em>--cached
</em> flag) or ask the diff logic to show any files
1719 that don
’t match the stat state as being
"tentatively changed". Both
1720 of these operations are very useful indeed.
</p></div>
1722 <h2 id=
"_cached_mode">Cached Mode
</h2>
1723 <div class=
"sectionbody">
1724 <div class=
"paragraph"><p>If
<em>--cached
</em> is specified, it allows you to ask:
</p></div>
1725 <div class=
"literalblock">
1726 <div class=
"content">
1727 <pre><tt>show me the differences between HEAD and the current index
1728 contents (the ones I'd write using 'git write-tree')
</tt></pre>
1730 <div class=
"paragraph"><p>For example, let
’s say that you have worked on your working directory, updated
1731 some files in the index and are ready to commit. You want to see exactly
1732 <strong>what
</strong> you are going to commit, without having to write a new tree
1733 object and compare it that way, and to do that, you just do
</p></div>
1734 <div class=
"literalblock">
1735 <div class=
"content">
1736 <pre><tt>git diff-index --cached HEAD
</tt></pre>
1738 <div class=
"paragraph"><p>Example: let
’s say I had renamed
<tt>commit.c
</tt> to
<tt>git-commit.c
</tt>, and I had
1739 done an
<tt>update-index
</tt> to make that effective in the index file.
1740 <tt>git diff-files
</tt> wouldn
’t show anything at all, since the index file
1741 matches my working directory. But doing a
<em>git diff-index
</em> does:
</p></div>
1742 <div class=
"literalblock">
1743 <div class=
"content">
1744 <pre><tt>torvalds@ppc970:~/git
> git diff-index --cached HEAD
1745 -
100644 blob
4161aecc6700a2eb579e842af0b7f22b98443f74 commit.c
1746 +
100644 blob
4161aecc6700a2eb579e842af0b7f22b98443f74 git-commit.c
</tt></pre>
1748 <div class=
"paragraph"><p>You can see easily that the above is a rename.
</p></div>
1749 <div class=
"paragraph"><p>In fact,
<tt>git diff-index --cached
</tt> <strong>should
</strong> always be entirely equivalent to
1750 actually doing a
<em>git write-tree
</em> and comparing that. Except this one is much
1751 nicer for the case where you just want to check where you are.
</p></div>
1752 <div class=
"paragraph"><p>So doing a
<tt>git diff-index --cached
</tt> is basically very useful when you are
1753 asking yourself
"what have I already marked for being committed, and
1754 what’s the difference to a previous tree".
</p></div>
1756 <h2 id=
"_non_cached_mode">Non-cached Mode
</h2>
1757 <div class=
"sectionbody">
1758 <div class=
"paragraph"><p>The
"non-cached" mode takes a different approach, and is potentially
1759 the more useful of the two in that what it does can
’t be emulated with
1760 a
<em>git write-tree
</em> +
<em>git diff-tree
</em>. Thus that
’s the default mode.
1761 The non-cached version asks the question:
</p></div>
1762 <div class=
"literalblock">
1763 <div class=
"content">
1764 <pre><tt>show me the differences between HEAD and the currently checked out
1765 tree - index contents _and_ files that aren't up-to-date
</tt></pre>
1767 <div class=
"paragraph"><p>which is obviously a very useful question too, since that tells you what
1768 you
<strong>could
</strong> commit. Again, the output matches the
<em>git diff-tree -r
</em>
1769 output to a tee, but with a twist.
</p></div>
1770 <div class=
"paragraph"><p>The twist is that if some file doesn
’t match the index, we don
’t have
1771 a backing store thing for it, and we use the magic
"all-zero" sha1 to
1772 show that. So let
’s say that you have edited
<tt>kernel/sched.c
</tt>, but
1773 have not actually done a
<em>git update-index
</em> on it yet - there is no
1774 "object" associated with the new state, and you get:
</p></div>
1775 <div class=
"literalblock">
1776 <div class=
"content">
1777 <pre><tt>torvalds@ppc970:~/v2.6/linux
> git diff-index HEAD
1778 *
100644-
>100664 blob
7476bb......-
>000000...... kernel/sched.c
</tt></pre>
1780 <div class=
"paragraph"><p>i.e., it shows that the tree has changed, and that
<tt>kernel/sched.c
</tt> has is
1781 not up-to-date and may contain new stuff. The all-zero sha1 means that to
1782 get the real diff, you need to look at the object in the working directory
1783 directly rather than do an object-to-object diff.
</p></div>
1784 <div class=
"admonitionblock">
1787 <div class=
"title">Note
</div>
1789 <td class=
"content">As with other commands of this type,
<em>git diff-index
</em> does not
1790 actually look at the contents of the file at all. So maybe
1791 <tt>kernel/sched.c
</tt> hasn
’t actually changed, and it
’s just that you
1792 touched it. In either case, it
’s a note that you need to
1793 <em>git update-index
</em> it to make the index be in sync.
</td>
1796 <div class=
"admonitionblock">
1799 <div class=
"title">Note
</div>
1801 <td class=
"content">You can have a mixture of files show up as
"has been updated"
1802 and
"is still dirty in the working directory" together. You can always
1803 tell which file is in which state, since the
"has been updated" ones
1804 show a valid sha1, and the
"not in sync with the index" ones will
1805 always have the special all-zero sha1.
</td>
1809 <h2 id=
"_git">GIT
</h2>
1810 <div class=
"sectionbody">
1811 <div class=
"paragraph"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
1814 <div id=
"footer-text">
1815 Last updated
2011-
03-
15 23:
30:
13 UTC