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[=
<limit
>]
521 Output the distribution of relative amount of changes (number of lines added or
522 removed) for each sub-directory. Directories with changes below
523 a cut-off percent (
3% by default) are not shown. The cut-off percent
524 can be set with
<tt>--dirstat=
<limit
></tt>. Changes in a child directory are not
525 counted for the parent directory, unless
<tt>--cumulative
</tt> is used.
529 --dirstat-by-file[=
<limit
>]
533 Same as
<tt>--dirstat
</tt>, but counts changed files instead of lines.
541 Output a condensed summary of extended header information
542 such as creations, renames and mode changes.
550 Synonym for
<tt>-p --stat
</tt>.
558 When
<tt>--raw
</tt>,
<tt>--numstat
</tt>,
<tt>--name-only
</tt> or
<tt>--name-status
</tt> has been
559 given, do not munge pathnames and use NULs as output field terminators.
561 <div class=
"paragraph"><p>Without this option, each pathname output will have TAB, LF, double quotes,
562 and backslash characters replaced with
<tt>\t
</tt>,
<tt>\n
</tt>,
<tt>\
"</tt>, and <tt>\\</tt>,
563 respectively, and the pathname will be enclosed in double quotes if
564 any of those replacements occurred.</p></div>
571 Show only names of changed files.
579 Show only names and status of changed files. See the description
580 of the <tt>--diff-filter</tt> option on what the status letters mean.
584 --submodule[=<format>]
588 Chose the output format for submodule differences. <format> can be one of
589 <em>short</em> and <em>log</em>. <em>short</em> just shows pairs of commit names, this format
590 is used when this option is not given. <em>log</em> is the default value for this
591 option and lists the commits in that commit range like the <em>summary</em>
592 option of <a href="git-submodule.html
">git-submodule(1)</a> does.
596 --color[=<when>]
601 The value must be always (the default), never, or auto.
609 Turn off colored diff, even when the configuration file
610 gives the default to color output.
611 Same as <tt>--color=never</tt>.
615 --word-diff[=<mode>]
619 Show a word diff, using the <mode> to delimit changed words.
620 By default, words are delimited by whitespace; see
621 <tt>--word-diff-regex</tt> below. The <mode> defaults to <em>plain</em>, and
624 <div class="dlist
"><dl>
630 Highlight changed words using only colors. Implies <tt>--color</tt>.
638 Show words as <tt>[-removed-]</tt> and <tt>{<tt>added</tt>}</tt>. Makes no
639 attempts to escape the delimiters if they appear in the input,
640 so the output may be ambiguous.
648 Use a special line-based format intended for script
649 consumption. Added/removed/unchanged runs are printed in the
650 usual unified diff format, starting with a <tt>+</tt>/<tt>-</tt>/` `
651 character at the beginning of the line and extending to the
652 end of the line. Newlines in the input are represented by a
653 tilde <tt>~</tt> on a line of its own.
661 Disable word diff again.
665 <div class="paragraph
"><p>Note that despite the name of the first mode, color is used to
666 highlight the changed parts in all modes if enabled.</p></div>
669 --word-diff-regex=<regex>
673 Use <regex> to decide what a word is, instead of considering
674 runs of non-whitespace to be a word. Also implies
675 <tt>--word-diff</tt> unless it was already enabled.
677 <div class="paragraph
"><p>Every non-overlapping match of the
678 <regex> is considered a word. Anything between these matches is
679 considered whitespace and ignored(!) for the purposes of finding
680 differences. You may want to append <tt>|[^[:space:]]</tt> to your regular
681 expression to make sure that it matches all non-whitespace characters.
682 A match that contains a newline is silently truncated(!) at the
684 <div class="paragraph
"><p>The regex can also be set via a diff driver or configuration option, see
685 <a href="gitattributes.html
">gitattributes(1)</a> or <a href="git-config.html
">git-config(1)</a>. Giving it explicitly
686 overrides any diff driver or configuration setting. Diff drivers
687 override configuration settings.</p></div>
690 --color-words[=<regex>]
694 Equivalent to <tt>--word-diff=color</tt> plus (if a regex was
695 specified) <tt>--word-diff-regex=<regex></tt>.
703 Turn off rename detection, even when the configuration
704 file gives the default to do so.
712 Warn if changes introduce trailing whitespace
713 or an indent that uses a space before a tab. Exits with
714 non-zero status if problems are found. Not compatible with
723 Instead of the first handful of characters, show the full
724 pre- and post-image blob object names on the "index
"
725 line when generating patch format output.
733 In addition to <tt>--full-index</tt>, output a binary diff that
734 can be applied with <tt>git-apply</tt>.
742 Instead of showing the full 40-byte hexadecimal object
743 name in diff-raw format output and diff-tree header
744 lines, show only a partial prefix. This is
745 independent of the <tt>--full-index</tt> option above, which controls
746 the diff-patch output format. Non default number of
747 digits can be specified with <tt>--abbrev=<n></tt>.
751 -B[<n>][/<m>]
754 --break-rewrites[=[<n>][/<m>]]
758 Break complete rewrite changes into pairs of delete and
759 create. This serves two purposes:
761 <div class="paragraph
"><p>It affects the way a change that amounts to a total rewrite of a file
762 not as a series of deletion and insertion mixed together with a very
763 few lines that happen to match textually as the context, but as a
764 single deletion of everything old followed by a single insertion of
765 everything new, and the number <tt>m</tt> controls this aspect of the -B
766 option (defaults to 60%). <tt>-B/70%</tt> specifies that less than 30% of the
767 original should remain in the result for git to consider it a total
768 rewrite (i.e. otherwise the resulting patch will be a series of
769 deletion and insertion mixed together with context lines).</p></div>
770 <div class="paragraph
"><p>When used with -M, a totally-rewritten file is also considered as the
771 source of a rename (usually -M only considers a file that disappeared
772 as the source of a rename), and the number <tt>n</tt> controls this aspect of
773 the -B option (defaults to 50%). <tt>-B20%</tt> specifies that a change with
774 addition and deletion compared to 20% or more of the file’s size are
775 eligible for being picked up as a possible source of a rename to
776 another file.</p></div>
782 --find-renames[=<n>]
787 If <tt>n</tt> is specified, it is a is a threshold on the similarity
788 index (i.e. amount of addition/deletions compared to the
789 file’s size). For example, <tt>-M90%</tt> means git should consider a
790 delete/add pair to be a rename if more than 90% of the file
791 hasn’t changed.
798 --find-copies[=<n>]
802 Detect copies as well as renames. See also <tt>--find-copies-harder</tt>.
803 If <tt>n</tt> is specified, it has the same meaning as for <tt>-M<n></tt>.
811 For performance reasons, by default, <tt>-C</tt> option finds copies only
812 if the original file of the copy was modified in the same
813 changeset. This flag makes the command
814 inspect unmodified files as candidates for the source of
815 copy. This is a very expensive operation for large
816 projects, so use it with caution. Giving more than one
817 <tt>-C</tt> option has the same effect.
825 The <tt>-M</tt> and <tt>-C</tt> options require O(n^2) processing time where n
826 is the number of potential rename/copy targets. This
827 option prevents rename/copy detection from running if
828 the number of rename/copy targets exceeds the specified
833 --diff-filter=[(A|C|D|M|R|T|U|X|B)…[*]]
837 Select only files that are Added (<tt>A</tt>), Copied (<tt>C</tt>),
838 Deleted (<tt>D</tt>), Modified (<tt>M</tt>), Renamed (<tt>R</tt>), have their
839 type (i.e. regular file, symlink, submodule, …) changed (<tt>T</tt>),
840 are Unmerged (<tt>U</tt>), are
841 Unknown (<tt>X</tt>), or have had their pairing Broken (<tt>B</tt>).
842 Any combination of the filter characters (including none) can be used.
843 When <tt>*</tt> (All-or-none) is added to the combination, all
844 paths are selected if there is any file that matches
845 other criteria in the comparison; if there is no file
846 that matches other criteria, nothing is selected.
854 Look for differences that introduce or remove an instance of
855 <string>. Note that this is different than the string simply
856 appearing in diff output; see the <em>pickaxe</em> entry in
857 <a href="gitdiffcore.html
">gitdiffcore(7)</a> for more details.
865 Look for differences whose added or removed line matches
866 the given <regex>.
874 When <tt>-S</tt> or <tt>-G</tt> finds a change, show all the changes in that
875 changeset, not just the files that contain the change
884 Make the <string> not a plain string but an extended POSIX
893 Output the patch in the order specified in the
894 <orderfile>, which has one shell glob pattern per line.
902 Swap two inputs; that is, show differences from index or
903 on-disk file to tree contents.
907 --relative[=<path>]
911 When run from a subdirectory of the project, it can be
912 told to exclude changes outside the directory and show
913 pathnames relative to it with this option. When you are
914 not in a subdirectory (e.g. in a bare repository), you
915 can name which subdirectory to make the output relative
916 to by giving a <path> as an argument.
927 Treat all files as text.
931 --ignore-space-at-eol
935 Ignore changes in whitespace at EOL.
942 --ignore-space-change
946 Ignore changes in amount of whitespace. This ignores whitespace
947 at line end, and considers all other sequences of one or
948 more whitespace characters to be equivalent.
959 Ignore whitespace when comparing lines. This ignores
960 differences even if one line has whitespace where the other
965 --inter-hunk-context=<lines>
969 Show the context between diff hunks, up to the specified number
970 of lines, thereby fusing hunks that are close to each other.
978 Make the program exit with codes similar to diff(1).
979 That is, it exits with 1 if there were differences and
980 0 means no differences.
988 Disable all output of the program. Implies <tt>--exit-code</tt>.
996 Allow an external diff helper to be executed. If you set an
997 external diff driver with <a href="gitattributes.html
">gitattributes(5)</a>, you need
998 to use this option with <a href="git-log.html
">git-log(1)</a> and friends.
1001 <dt class="hdlist1
">
1006 Disallow external diff drivers.
1009 <dt class="hdlist1
">
1010 --ignore-submodules[=<when>]
1014 Ignore changes to submodules in the diff generation. <when> can be
1015 either "none
", "untracked
", "dirty
" or "all
", which is the default
1016 Using "none
" will consider the submodule modified when it either contains
1017 untracked or modified files or its HEAD differs from the commit recorded
1018 in the superproject and can be used to override any settings of the
1019 <em>ignore</em> option in <a href="git-config.html
">git-config(1)</a> or <a href="gitmodules.html
">gitmodules(5)</a>. When
1020 "untracked
" is used submodules are not considered dirty when they only
1021 contain untracked content (but they are still scanned for modified
1022 content). Using "dirty
" ignores all changes to the work tree of submodules,
1023 only changes to the commits stored in the superproject are shown (this was
1024 the behavior until 1.7.0). Using "all
" hides all changes to submodules.
1027 <dt class="hdlist1
">
1028 --src-prefix=<prefix>
1032 Show the given source prefix instead of "a/
".
1035 <dt class="hdlist1
">
1036 --dst-prefix=<prefix>
1040 Show the given destination prefix instead of "b/
".
1043 <dt class="hdlist1
">
1048 Do not show any source or destination prefix.
1052 <div class="paragraph
"><p>For more detailed explanation on these common options, see also
1053 <a href="gitdiffcore.html
">gitdiffcore(7)</a>.</p></div>
1054 <div class="dlist
"><dl>
1055 <dt class="hdlist1
">
1060 The id of a tree object to diff against.
1063 <dt class="hdlist1
">
1068 do not consider the on-disk file at all
1071 <dt class="hdlist1
">
1076 By default, files recorded in the index but not checked
1077 out are reported as deleted. This flag makes
1078 <em>git diff-index</em> say that all non-checked-out files are up
1084 <h2 id="_raw_output_format
">Raw output format</h2>
1085 <div class="sectionbody
">
1086 <div class="paragraph
"><p>The raw output format from "git-diff-index
", "git-diff-tree
",
1087 "git-diff-files
" and "git diff --raw
" are very similar.</p></div>
1088 <div class="paragraph
"><p>These commands all compare two sets of things; what is
1089 compared differs:</p></div>
1090 <div class="dlist
"><dl>
1091 <dt class="hdlist1
">
1092 git-diff-index <tree-ish>
1096 compares the <tree-ish> and the files on the filesystem.
1099 <dt class="hdlist1
">
1100 git-diff-index --cached <tree-ish>
1104 compares the <tree-ish> and the index.
1107 <dt class="hdlist1
">
1108 git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>…]
1112 compares the trees named by the two arguments.
1115 <dt class="hdlist1
">
1116 git-diff-files [<pattern>…]
1120 compares the index and the files on the filesystem.
1124 <div class="paragraph
"><p>The "git-diff-tree
" command begins its output by printing the hash of
1125 what is being compared. After that, all the commands print one output
1126 line per changed file.</p></div>
1127 <div class="paragraph
"><p>An output line is formatted this way:</p></div>
1128 <div class="listingblock
">
1129 <div class="content
">
1130 <pre><tt>in-place edit :100644 100644 bcd1234... 0123456... M file0
1131 copy-edit :100644 100644 abcd123... 1234567... C68 file1 file2
1132 rename-edit :100644 100644 abcd123... 1234567... R86 file1 file3
1133 create :000000 100644 0000000... 1234567... A file4
1134 delete :100644 000000 1234567... 0000000... D file5
1135 unmerged :000000 000000 0000000... 0000000... U file6</tt></pre>
1137 <div class="paragraph
"><p>That is, from the left to the right:</p></div>
1138 <div class="olist arabic
"><ol class="arabic
">
1146 mode for "src
"; 000000 if creation or unmerged.
1156 mode for "dst
"; 000000 if deletion or unmerged.
1166 sha1 for "src
"; 0{40} if creation or unmerged.
1176 sha1 for "dst
"; 0{40} if creation, unmerged or "look at work tree
".
1186 status, followed by optional "score
" number.
1191 a tab or a NUL when <em>-z</em> option is used.
1201 a tab or a NUL when <em>-z</em> option is used; only exists for C or R.
1206 path for "dst
"; only exists for C or R.
1211 an LF or a NUL when <em>-z</em> option is used, to terminate the record.
1215 <div class="paragraph
"><p>Possible status letters are:</p></div>
1216 <div class="ulist
"><ul>
1219 A: addition of a file
1224 C: copy of a file into a new one
1229 D: deletion of a file
1234 M: modification of the contents or mode of a file
1239 R: renaming of a file
1244 T: change in the type of the file
1249 U: file is unmerged (you must complete the merge before it can
1255 X: "unknown
" change type (most probably a bug, please report it)
1259 <div class="paragraph
"><p>Status letters C and R are always followed by a score (denoting the
1260 percentage of similarity between the source and target of the move or
1261 copy), and are the only ones to be so.</p></div>
1262 <div class="paragraph
"><p><sha1> is shown as all 0’s if a file is new on the filesystem
1263 and it is out of sync with the index.</p></div>
1264 <div class="paragraph
"><p>Example:</p></div>
1265 <div class="listingblock
">
1266 <div class="content
">
1267 <pre><tt>:100644 100644 5be4a4...... 000000...... M file.c</tt></pre>
1269 <div class="paragraph
"><p>When <tt>-z</tt> option is not used, TAB, LF, and backslash characters
1270 in pathnames are represented as <tt>\t</tt>, <tt>\n</tt>, and <tt>\\</tt>,
1271 respectively.</p></div>
1273 <h2 id="_diff_format_for_merges
">diff format for merges</h2>
1274 <div class="sectionbody
">
1275 <div class="paragraph
"><p>"git-diff-tree
", "git-diff-files
" and "git-diff --raw
"
1276 can take <em>-c</em> or <em>--cc</em> option
1277 to generate diff output also for merge commits. The output differs
1278 from the format described above in the following way:</p></div>
1279 <div class="olist arabic
"><ol class="arabic
">
1282 there is a colon for each parent
1287 there are more "src
" modes and "src
" sha1
1292 status is concatenated status characters for each parent
1297 no optional "score
" number
1302 single path, only for "dst
"
1306 <div class="paragraph
"><p>Example:</p></div>
1307 <div class="listingblock
">
1308 <div class="content
">
1309 <pre><tt>::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM describe.c</tt></pre>
1311 <div class="paragraph
"><p>Note that <em>combined diff</em> lists only files which were modified from
1312 all parents.</p></div>
1314 <h2 id="_generating_patches_with_p
">Generating patches with -p</h2>
1315 <div class="sectionbody
">
1316 <div class="paragraph
"><p>When "git-diff-index
", "git-diff-tree
", or "git-diff-files
" are run
1317 with a <em>-p</em> option, "git diff
" without the <em>--raw</em> option, or
1318 "git log
" with the "-p
" option, they
1319 do not produce the output described above; instead they produce a
1320 patch file. You can customize the creation of such patches via the
1321 GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables.</p></div>
1322 <div class="paragraph
"><p>What the -p option produces is slightly different from the traditional
1323 diff format:</p></div>
1324 <div class="olist arabic
"><ol class="arabic
">
1327 It is preceded with a "git diff
" header that looks like this:
1329 <div class="literalblock
">
1330 <div class="content
">
1331 <pre><tt>diff --git a/file1 b/file2</tt></pre>
1333 <div class="paragraph
"><p>The <tt>a/</tt> and <tt>b/</tt> filenames are the same unless rename/copy is
1334 involved. Especially, even for a creation or a deletion,
1335 <tt>/dev/null</tt> is <em>not</em> used in place of the <tt>a/</tt> or <tt>b/</tt> filenames.</p></div>
1336 <div class="paragraph
"><p>When rename/copy is involved, <tt>file1</tt> and <tt>file2</tt> show the
1337 name of the source file of the rename/copy and the name of
1338 the file that rename/copy produces, respectively.</p></div>
1342 It is followed by one or more extended header lines:
1344 <div class="literalblock
">
1345 <div class="content
">
1346 <pre><tt>old mode <mode>
1347 new mode <mode>
1348 deleted file mode <mode>
1349 new file mode <mode>
1350 copy from <path>
1351 copy to <path>
1352 rename from <path>
1353 rename to <path>
1354 similarity index <number>
1355 dissimilarity index <number>
1356 index <hash>..<hash> <mode></tt></pre>
1358 <div class="paragraph
"><p>File modes are printed as 6-digit octal numbers including the file type
1359 and file permission bits.</p></div>
1360 <div class="paragraph
"><p>Path names in extended headers do not include the <tt>a/</tt> and <tt>b/</tt> prefixes.</p></div>
1361 <div class="paragraph
"><p>The similarity index is the percentage of unchanged lines, and
1362 the dissimilarity index is the percentage of changed lines. It
1363 is a rounded down integer, followed by a percent sign. The
1364 similarity index value of 100% is thus reserved for two equal
1365 files, while 100% dissimilarity means that no line from the old
1366 file made it into the new one.</p></div>
1367 <div class="paragraph
"><p>The index line includes the SHA-1 checksum before and after the change.
1368 The <mode> is included if the file mode does not change; otherwise,
1369 separate lines indicate the old and the new mode.</p></div>
1373 TAB, LF, double quote and backslash characters in pathnames
1374 are represented as <tt>\t</tt>, <tt>\n</tt>, <tt>\"</tt> and
<tt>\\
</tt>, respectively.
1375 If there is need for such substitution then the whole
1376 pathname is put in double quotes.
1381 All the
<tt>file1
</tt> files in the output refer to files before the
1382 commit, and all the
<tt>file2
</tt> files refer to files after the commit.
1383 It is incorrect to apply each change to each file sequentially. For
1384 example, this patch will swap a and b:
1386 <div class=
"literalblock">
1387 <div class=
"content">
1388 <pre><tt>diff --git a/a b/b
1393 rename to a
</tt></pre>
1398 <h2 id=
"_combined_diff_format">combined diff format
</h2>
1399 <div class=
"sectionbody">
1400 <div class=
"paragraph"><p>"git-diff-tree",
"git-diff-files" and
"git-diff" can take
<em>-c
</em> or
1401 <em>--cc
</em> option to produce
<em>combined diff
</em>. For showing a merge commit
1402 with
"git log -p", this is the default format; you can force showing
1403 full diff with the
<em>-m
</em> option.
1404 A
<em>combined diff
</em> format looks like this:
</p></div>
1405 <div class=
"listingblock">
1406 <div class=
"content">
1407 <pre><tt>diff --combined describe.c
1408 index fabadb8,cc95eb0.
.4866510
1411 @@@ -
98,
20 -
98,
12 +
98,
20 @@@
1412 return (a_date
> b_date) ? -
1 : (a_date == b_date) ?
0 :
1;
1415 - static void describe(char *arg)
1416 -static void describe(struct commit *cmit, int last_one)
1417 ++static void describe(char *arg, int last_one)
1419 + unsigned char sha1[
20];
1420 + struct commit *cmit;
1421 struct commit_list *list;
1422 static int initialized =
0;
1423 struct commit_name *n;
1425 + if (get_sha1(arg, sha1)
< 0)
1426 + usage(describe_usage);
1427 + cmit = lookup_commit_reference(sha1);
1429 + usage(describe_usage);
1433 for_each_ref(get_name);
</tt></pre>
1435 <div class=
"olist arabic"><ol class=
"arabic">
1438 It is preceded with a
"git diff" header, that looks like
1439 this (when
<em>-c
</em> option is used):
1441 <div class=
"literalblock">
1442 <div class=
"content">
1443 <pre><tt>diff --combined file
</tt></pre>
1445 <div class=
"paragraph"><p>or like this (when
<em>--cc
</em> option is used):
</p></div>
1446 <div class=
"literalblock">
1447 <div class=
"content">
1448 <pre><tt>diff --cc file
</tt></pre>
1453 It is followed by one or more extended header lines
1454 (this example shows a merge with two parents):
1456 <div class=
"literalblock">
1457 <div class=
"content">
1458 <pre><tt>index
<hash
>,
<hash
>..
<hash
>
1459 mode
<mode
>,
<mode
>..
<mode
>
1460 new file mode
<mode
>
1461 deleted file mode
<mode
>,
<mode
></tt></pre>
1463 <div class=
"paragraph"><p>The
<tt>mode
<mode
>,
<mode
>..
<mode
></tt> line appears only if at least one of
1464 the
<mode
> is different from the rest. Extended headers with
1465 information about detected contents movement (renames and
1466 copying detection) are designed to work with diff of two
1467 <tree-ish
> and are not used by combined diff format.
</p></div>
1471 It is followed by two-line from-file/to-file header
1473 <div class=
"literalblock">
1474 <div class=
"content">
1476 +++ b/file
</tt></pre>
1478 <div class=
"paragraph"><p>Similar to two-line header for traditional
<em>unified
</em> diff
1479 format,
<tt>/dev/null
</tt> is used to signal created or deleted
1484 Chunk header format is modified to prevent people from
1485 accidentally feeding it to
<tt>patch -p1
</tt>. Combined diff format
1486 was created for review of merge commit changes, and was not
1487 meant for apply. The change is similar to the change in the
1488 extended
<em>index
</em> header:
1490 <div class=
"literalblock">
1491 <div class=
"content">
1492 <pre><tt>@@@
<from-file-range
> <from-file-range
> <to-file-range
> @@@
</tt></pre>
1494 <div class=
"paragraph"><p>There are (number of parents +
1)
<tt>@
</tt> characters in the chunk
1495 header for combined diff format.
</p></div>
1498 <div class=
"paragraph"><p>Unlike the traditional
<em>unified
</em> diff format, which shows two
1499 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
1500 added to B), or
<tt>" "</tt> (space
 — unchanged) prefix, this format
1501 compares two or more files file1, file2,
… with one file X, and
1502 shows how X differs from each of fileN. One column for each of
1503 fileN is prepended to the output line to note how X
’s line is
1504 different from it.
</p></div>
1505 <div class=
"paragraph"><p>A
<tt>-
</tt> character in the column N means that the line appears in
1506 fileN but it does not appear in the result. A
<tt>+
</tt> character
1507 in the column N means that the line appears in the result,
1508 and fileN does not have that line (in other words, the line was
1509 added, from the point of view of that parent).
</p></div>
1510 <div class=
"paragraph"><p>In the above example output, the function signature was changed
1511 from both files (hence two
<tt>-
</tt> removals from both file1 and
1512 file2, plus
<tt>++
</tt> to mean one line that was added does not appear
1513 in either file1 nor file2). Also eight other lines are the same
1514 from file1 but do not appear in file2 (hence prefixed with
<tt>+</tt>).
</p></div>
1515 <div class=
"paragraph"><p>When shown by
<tt>git diff-tree -c
</tt>, it compares the parents of a
1516 merge commit with the merge result (i.e. file1..fileN are the
1517 parents). When shown by
<tt>git diff-files -c
</tt>, it compares the
1518 two unresolved merge parents with the working tree file
1519 (i.e. file1 is stage
2 aka
"our version", file2 is stage
3 aka
1520 "their version").
</p></div>
1522 <h2 id=
"_other_diff_formats">other diff formats
</h2>
1523 <div class=
"sectionbody">
1524 <div class=
"paragraph"><p>The
<tt>--summary
</tt> option describes newly added, deleted, renamed and
1525 copied files. The
<tt>--stat
</tt> option adds diffstat(
1) graph to the
1526 output. These options can be combined with other options, such as
1527 <tt>-p
</tt>, and are meant for human consumption.
</p></div>
1528 <div class=
"paragraph"><p>When showing a change that involves a rename or a copy,
<tt>--stat
</tt> output
1529 formats the pathnames compactly by combining common prefix and suffix of
1530 the pathnames. For example, a change that moves
<tt>arch/i386/Makefile
</tt> to
1531 <tt>arch/x86/Makefile
</tt> while modifying
4 lines will be shown like this:
</p></div>
1532 <div class=
"listingblock">
1533 <div class=
"content">
1534 <pre><tt>arch/{i386 =
> x86}/Makefile |
4 +--
</tt></pre>
1536 <div class=
"paragraph"><p>The
<tt>--numstat
</tt> option gives the diffstat(
1) information but is designed
1537 for easier machine consumption. An entry in
<tt>--numstat
</tt> output looks
1538 like this:
</p></div>
1539 <div class=
"listingblock">
1540 <div class=
"content">
1542 3 1 arch/{i386 =
> x86}/Makefile
</tt></pre>
1544 <div class=
"paragraph"><p>That is, from left to right:
</p></div>
1545 <div class=
"olist arabic"><ol class=
"arabic">
1548 the number of added lines;
1558 the number of deleted lines;
1568 pathname (possibly with rename/copy information);
1577 <div class=
"paragraph"><p>When
<tt>-z
</tt> output option is in effect, the output is formatted this way:
</p></div>
1578 <div class=
"listingblock">
1579 <div class=
"content">
1580 <pre><tt>1 2 README NUL
1581 3 1 NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
</tt></pre>
1583 <div class=
"paragraph"><p>That is:
</p></div>
1584 <div class=
"olist arabic"><ol class=
"arabic">
1587 the number of added lines;
1597 the number of deleted lines;
1607 a NUL (only exists if renamed/copied);
1612 pathname in preimage;
1617 a NUL (only exists if renamed/copied);
1622 pathname in postimage (only exists if renamed/copied);
1631 <div class=
"paragraph"><p>The extra
<tt>NUL
</tt> before the preimage path in renamed case is to allow
1632 scripts that read the output to tell if the current record being read is
1633 a single-path record or a rename/copy record without reading ahead.
1634 After reading added and deleted lines, reading up to
<tt>NUL
</tt> would yield
1635 the pathname, but if that is
<tt>NUL
</tt>, the record will show two paths.
</p></div>
1637 <h2 id=
"_operating_modes">Operating Modes
</h2>
1638 <div class=
"sectionbody">
1639 <div class=
"paragraph"><p>You can choose whether you want to trust the index file entirely
1640 (using the
<em>--cached
</em> flag) or ask the diff logic to show any files
1641 that don
’t match the stat state as being
"tentatively changed". Both
1642 of these operations are very useful indeed.
</p></div>
1644 <h2 id=
"_cached_mode">Cached Mode
</h2>
1645 <div class=
"sectionbody">
1646 <div class=
"paragraph"><p>If
<em>--cached
</em> is specified, it allows you to ask:
</p></div>
1647 <div class=
"literalblock">
1648 <div class=
"content">
1649 <pre><tt>show me the differences between HEAD and the current index
1650 contents (the ones I'd write using 'git write-tree')
</tt></pre>
1652 <div class=
"paragraph"><p>For example, let
’s say that you have worked on your working directory, updated
1653 some files in the index and are ready to commit. You want to see exactly
1654 <strong>what
</strong> you are going to commit, without having to write a new tree
1655 object and compare it that way, and to do that, you just do
</p></div>
1656 <div class=
"literalblock">
1657 <div class=
"content">
1658 <pre><tt>git diff-index --cached HEAD
</tt></pre>
1660 <div class=
"paragraph"><p>Example: let
’s say I had renamed
<tt>commit.c
</tt> to
<tt>git-commit.c
</tt>, and I had
1661 done an
<tt>update-index
</tt> to make that effective in the index file.
1662 <tt>git diff-files
</tt> wouldn
’t show anything at all, since the index file
1663 matches my working directory. But doing a
<em>git diff-index
</em> does:
</p></div>
1664 <div class=
"literalblock">
1665 <div class=
"content">
1666 <pre><tt>torvalds@ppc970:~/git
> git diff-index --cached HEAD
1667 -
100644 blob
4161aecc6700a2eb579e842af0b7f22b98443f74 commit.c
1668 +
100644 blob
4161aecc6700a2eb579e842af0b7f22b98443f74 git-commit.c
</tt></pre>
1670 <div class=
"paragraph"><p>You can see easily that the above is a rename.
</p></div>
1671 <div class=
"paragraph"><p>In fact,
<tt>git diff-index --cached
</tt> <strong>should
</strong> always be entirely equivalent to
1672 actually doing a
<em>git write-tree
</em> and comparing that. Except this one is much
1673 nicer for the case where you just want to check where you are.
</p></div>
1674 <div class=
"paragraph"><p>So doing a
<tt>git diff-index --cached
</tt> is basically very useful when you are
1675 asking yourself
"what have I already marked for being committed, and
1676 what’s the difference to a previous tree".
</p></div>
1678 <h2 id=
"_non_cached_mode">Non-cached Mode
</h2>
1679 <div class=
"sectionbody">
1680 <div class=
"paragraph"><p>The
"non-cached" mode takes a different approach, and is potentially
1681 the more useful of the two in that what it does can
’t be emulated with
1682 a
<em>git write-tree
</em> +
<em>git diff-tree
</em>. Thus that
’s the default mode.
1683 The non-cached version asks the question:
</p></div>
1684 <div class=
"literalblock">
1685 <div class=
"content">
1686 <pre><tt>show me the differences between HEAD and the currently checked out
1687 tree - index contents _and_ files that aren't up-to-date
</tt></pre>
1689 <div class=
"paragraph"><p>which is obviously a very useful question too, since that tells you what
1690 you
<strong>could
</strong> commit. Again, the output matches the
<em>git diff-tree -r
</em>
1691 output to a tee, but with a twist.
</p></div>
1692 <div class=
"paragraph"><p>The twist is that if some file doesn
’t match the index, we don
’t have
1693 a backing store thing for it, and we use the magic
"all-zero" sha1 to
1694 show that. So let
’s say that you have edited
<tt>kernel/sched.c
</tt>, but
1695 have not actually done a
<em>git update-index
</em> on it yet - there is no
1696 "object" associated with the new state, and you get:
</p></div>
1697 <div class=
"literalblock">
1698 <div class=
"content">
1699 <pre><tt>torvalds@ppc970:~/v2.6/linux
> git diff-index HEAD
1700 *
100644-
>100664 blob
7476bb......-
>000000...... kernel/sched.c
</tt></pre>
1702 <div class=
"paragraph"><p>i.e., it shows that the tree has changed, and that
<tt>kernel/sched.c
</tt> has is
1703 not up-to-date and may contain new stuff. The all-zero sha1 means that to
1704 get the real diff, you need to look at the object in the working directory
1705 directly rather than do an object-to-object diff.
</p></div>
1706 <div class=
"admonitionblock">
1709 <div class=
"title">Note
</div>
1711 <td class=
"content">As with other commands of this type,
<em>git diff-index
</em> does not
1712 actually look at the contents of the file at all. So maybe
1713 <tt>kernel/sched.c
</tt> hasn
’t actually changed, and it
’s just that you
1714 touched it. In either case, it
’s a note that you need to
1715 <em>git update-index
</em> it to make the index be in sync.
</td>
1718 <div class=
"admonitionblock">
1721 <div class=
"title">Note
</div>
1723 <td class=
"content">You can have a mixture of files show up as
"has been updated"
1724 and
"is still dirty in the working directory" together. You can always
1725 tell which file is in which state, since the
"has been updated" ones
1726 show a valid sha1, and the
"not in sync with the index" ones will
1727 always have the special all-zero sha1.
</td>
1731 <h2 id=
"_author">Author
</h2>
1732 <div class=
"sectionbody">
1733 <div class=
"paragraph"><p>Written by Linus Torvalds
<<a href=
"mailto:torvalds@osdl.org">torvalds@osdl.org
</a>></p></div>
1735 <h2 id=
"_documentation">Documentation
</h2>
1736 <div class=
"sectionbody">
1737 <div class=
"paragraph"><p>Documentation by David Greaves, Junio C Hamano and the git-list
<<a href=
"mailto:git@vger.kernel.org">git@vger.kernel.org
</a>>.
</p></div>
1739 <h2 id=
"_git">GIT
</h2>
1740 <div class=
"sectionbody">
1741 <div class=
"paragraph"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
1744 <div id=
"footer-text">
1745 Last updated
2010-
01-
21 17:
44:
19 UTC