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.
527 <div class=
"paragraph"><p>Note that the
<tt>--dirstat
</tt> option computes the changes while ignoring
528 the amount of pure code movements within a file. In other words,
529 rearranging lines in a file is not counted as much as other changes.
</p></div>
532 --dirstat-by-file[=
<limit
>]
536 Same as
<tt>--dirstat
</tt>, but counts changed files instead of lines.
544 Output a condensed summary of extended header information
545 such as creations, renames and mode changes.
553 Synonym for
<tt>-p --stat
</tt>.
561 When
<tt>--raw
</tt>,
<tt>--numstat
</tt>,
<tt>--name-only
</tt> or
<tt>--name-status
</tt> has been
562 given, do not munge pathnames and use NULs as output field terminators.
564 <div class=
"paragraph"><p>Without this option, each pathname output will have TAB, LF, double quotes,
565 and backslash characters replaced with
<tt>\t
</tt>,
<tt>\n
</tt>,
<tt>\
"</tt>, and <tt>\\</tt>,
566 respectively, and the pathname will be enclosed in double quotes if
567 any of those replacements occurred.</p></div>
574 Show only names of changed files.
582 Show only names and status of changed files. See the description
583 of the <tt>--diff-filter</tt> option on what the status letters mean.
587 --submodule[=<format>]
591 Chose the output format for submodule differences. <format> can be one of
592 <em>short</em> and <em>log</em>. <em>short</em> just shows pairs of commit names, this format
593 is used when this option is not given. <em>log</em> is the default value for this
594 option and lists the commits in that commit range like the <em>summary</em>
595 option of <a href="git-submodule.html
">git-submodule(1)</a> does.
599 --color[=<when>]
604 The value must be always (the default), never, or auto.
612 Turn off colored diff, even when the configuration file
613 gives the default to color output.
614 Same as <tt>--color=never</tt>.
618 --word-diff[=<mode>]
622 Show a word diff, using the <mode> to delimit changed words.
623 By default, words are delimited by whitespace; see
624 <tt>--word-diff-regex</tt> below. The <mode> defaults to <em>plain</em>, and
627 <div class="dlist
"><dl>
633 Highlight changed words using only colors. Implies <tt>--color</tt>.
641 Show words as <tt>[-removed-]</tt> and <tt>{<tt>added</tt>}</tt>. Makes no
642 attempts to escape the delimiters if they appear in the input,
643 so the output may be ambiguous.
651 Use a special line-based format intended for script
652 consumption. Added/removed/unchanged runs are printed in the
653 usual unified diff format, starting with a <tt>+</tt>/<tt>-</tt>/` `
654 character at the beginning of the line and extending to the
655 end of the line. Newlines in the input are represented by a
656 tilde <tt>~</tt> on a line of its own.
664 Disable word diff again.
668 <div class="paragraph
"><p>Note that despite the name of the first mode, color is used to
669 highlight the changed parts in all modes if enabled.</p></div>
672 --word-diff-regex=<regex>
676 Use <regex> to decide what a word is, instead of considering
677 runs of non-whitespace to be a word. Also implies
678 <tt>--word-diff</tt> unless it was already enabled.
680 <div class="paragraph
"><p>Every non-overlapping match of the
681 <regex> is considered a word. Anything between these matches is
682 considered whitespace and ignored(!) for the purposes of finding
683 differences. You may want to append <tt>|[^[:space:]]</tt> to your regular
684 expression to make sure that it matches all non-whitespace characters.
685 A match that contains a newline is silently truncated(!) at the
687 <div class="paragraph
"><p>The regex can also be set via a diff driver or configuration option, see
688 <a href="gitattributes.html
">gitattributes(1)</a> or <a href="git-config.html
">git-config(1)</a>. Giving it explicitly
689 overrides any diff driver or configuration setting. Diff drivers
690 override configuration settings.</p></div>
693 --color-words[=<regex>]
697 Equivalent to <tt>--word-diff=color</tt> plus (if a regex was
698 specified) <tt>--word-diff-regex=<regex></tt>.
706 Turn off rename detection, even when the configuration
707 file gives the default to do so.
715 Warn if changes introduce trailing whitespace
716 or an indent that uses a space before a tab. Exits with
717 non-zero status if problems are found. Not compatible with
726 Instead of the first handful of characters, show the full
727 pre- and post-image blob object names on the "index
"
728 line when generating patch format output.
736 In addition to <tt>--full-index</tt>, output a binary diff that
737 can be applied with <tt>git-apply</tt>.
745 Instead of showing the full 40-byte hexadecimal object
746 name in diff-raw format output and diff-tree header
747 lines, show only a partial prefix. This is
748 independent of the <tt>--full-index</tt> option above, which controls
749 the diff-patch output format. Non default number of
750 digits can be specified with <tt>--abbrev=<n></tt>.
754 -B[<n>][/<m>]
757 --break-rewrites[=[<n>][/<m>]]
761 Break complete rewrite changes into pairs of delete and
762 create. This serves two purposes:
764 <div class="paragraph
"><p>It affects the way a change that amounts to a total rewrite of a file
765 not as a series of deletion and insertion mixed together with a very
766 few lines that happen to match textually as the context, but as a
767 single deletion of everything old followed by a single insertion of
768 everything new, and the number <tt>m</tt> controls this aspect of the -B
769 option (defaults to 60%). <tt>-B/70%</tt> specifies that less than 30% of the
770 original should remain in the result for git to consider it a total
771 rewrite (i.e. otherwise the resulting patch will be a series of
772 deletion and insertion mixed together with context lines).</p></div>
773 <div class="paragraph
"><p>When used with -M, a totally-rewritten file is also considered as the
774 source of a rename (usually -M only considers a file that disappeared
775 as the source of a rename), and the number <tt>n</tt> controls this aspect of
776 the -B option (defaults to 50%). <tt>-B20%</tt> specifies that a change with
777 addition and deletion compared to 20% or more of the file’s size are
778 eligible for being picked up as a possible source of a rename to
779 another file.</p></div>
785 --find-renames[=<n>]
790 If <tt>n</tt> is specified, it is a is a threshold on the similarity
791 index (i.e. amount of addition/deletions compared to the
792 file’s size). For example, <tt>-M90%</tt> means git should consider a
793 delete/add pair to be a rename if more than 90% of the file
794 hasn’t changed.
801 --find-copies[=<n>]
805 Detect copies as well as renames. See also <tt>--find-copies-harder</tt>.
806 If <tt>n</tt> is specified, it has the same meaning as for <tt>-M<n></tt>.
814 For performance reasons, by default, <tt>-C</tt> option finds copies only
815 if the original file of the copy was modified in the same
816 changeset. This flag makes the command
817 inspect unmodified files as candidates for the source of
818 copy. This is a very expensive operation for large
819 projects, so use it with caution. Giving more than one
820 <tt>-C</tt> option has the same effect.
827 --irreversible-delete
831 Omit the preimage for deletes, i.e. print only the header but not
832 the diff between the preimage and <tt>/dev/null</tt>. The resulting patch
833 is not meant to be applied with <tt>patch</tt> nor <tt>git apply</tt>; this is
834 solely for people who want to just concentrate on reviewing the
835 text after the change. In addition, the output obviously lack
836 enough information to apply such a patch in reverse, even manually,
837 hence the name of the option.
839 <div class="paragraph
"><p>When used together with <tt>-B</tt>, omit also the preimage in the deletion part
840 of a delete/create pair.</p></div>
847 The <tt>-M</tt> and <tt>-C</tt> options require O(n^2) processing time where n
848 is the number of potential rename/copy targets. This
849 option prevents rename/copy detection from running if
850 the number of rename/copy targets exceeds the specified
855 --diff-filter=[(A|C|D|M|R|T|U|X|B)…[*]]
859 Select only files that are Added (<tt>A</tt>), Copied (<tt>C</tt>),
860 Deleted (<tt>D</tt>), Modified (<tt>M</tt>), Renamed (<tt>R</tt>), have their
861 type (i.e. regular file, symlink, submodule, …) changed (<tt>T</tt>),
862 are Unmerged (<tt>U</tt>), are
863 Unknown (<tt>X</tt>), or have had their pairing Broken (<tt>B</tt>).
864 Any combination of the filter characters (including none) can be used.
865 When <tt>*</tt> (All-or-none) is added to the combination, all
866 paths are selected if there is any file that matches
867 other criteria in the comparison; if there is no file
868 that matches other criteria, nothing is selected.
876 Look for differences that introduce or remove an instance of
877 <string>. Note that this is different than the string simply
878 appearing in diff output; see the <em>pickaxe</em> entry in
879 <a href="gitdiffcore.html
">gitdiffcore(7)</a> for more details.
887 Look for differences whose added or removed line matches
888 the given <regex>.
896 When <tt>-S</tt> or <tt>-G</tt> finds a change, show all the changes in that
897 changeset, not just the files that contain the change
906 Make the <string> not a plain string but an extended POSIX
915 Output the patch in the order specified in the
916 <orderfile>, which has one shell glob pattern per line.
924 Swap two inputs; that is, show differences from index or
925 on-disk file to tree contents.
929 --relative[=<path>]
933 When run from a subdirectory of the project, it can be
934 told to exclude changes outside the directory and show
935 pathnames relative to it with this option. When you are
936 not in a subdirectory (e.g. in a bare repository), you
937 can name which subdirectory to make the output relative
938 to by giving a <path> as an argument.
949 Treat all files as text.
953 --ignore-space-at-eol
957 Ignore changes in whitespace at EOL.
964 --ignore-space-change
968 Ignore changes in amount of whitespace. This ignores whitespace
969 at line end, and considers all other sequences of one or
970 more whitespace characters to be equivalent.
981 Ignore whitespace when comparing lines. This ignores
982 differences even if one line has whitespace where the other
987 --inter-hunk-context=<lines>
991 Show the context between diff hunks, up to the specified number
992 of lines, thereby fusing hunks that are close to each other.
1000 Make the program exit with codes similar to diff(1).
1001 That is, it exits with 1 if there were differences and
1002 0 means no differences.
1005 <dt class="hdlist1
">
1010 Disable all output of the program. Implies <tt>--exit-code</tt>.
1013 <dt class="hdlist1
">
1018 Allow an external diff helper to be executed. If you set an
1019 external diff driver with <a href="gitattributes.html
">gitattributes(5)</a>, you need
1020 to use this option with <a href="git-log.html
">git-log(1)</a> and friends.
1023 <dt class="hdlist1
">
1028 Disallow external diff drivers.
1031 <dt class="hdlist1
">
1032 --ignore-submodules[=<when>]
1036 Ignore changes to submodules in the diff generation. <when> can be
1037 either "none
", "untracked
", "dirty
" or "all
", which is the default
1038 Using "none
" will consider the submodule modified when it either contains
1039 untracked or modified files or its HEAD differs from the commit recorded
1040 in the superproject and can be used to override any settings of the
1041 <em>ignore</em> option in <a href="git-config.html
">git-config(1)</a> or <a href="gitmodules.html
">gitmodules(5)</a>. When
1042 "untracked
" is used submodules are not considered dirty when they only
1043 contain untracked content (but they are still scanned for modified
1044 content). Using "dirty
" ignores all changes to the work tree of submodules,
1045 only changes to the commits stored in the superproject are shown (this was
1046 the behavior until 1.7.0). Using "all
" hides all changes to submodules.
1049 <dt class="hdlist1
">
1050 --src-prefix=<prefix>
1054 Show the given source prefix instead of "a/
".
1057 <dt class="hdlist1
">
1058 --dst-prefix=<prefix>
1062 Show the given destination prefix instead of "b/
".
1065 <dt class="hdlist1
">
1070 Do not show any source or destination prefix.
1074 <div class="paragraph
"><p>For more detailed explanation on these common options, see also
1075 <a href="gitdiffcore.html
">gitdiffcore(7)</a>.</p></div>
1076 <div class="dlist
"><dl>
1077 <dt class="hdlist1
">
1082 The id of a tree object to diff against.
1085 <dt class="hdlist1
">
1090 do not consider the on-disk file at all
1093 <dt class="hdlist1
">
1098 By default, files recorded in the index but not checked
1099 out are reported as deleted. This flag makes
1100 <em>git diff-index</em> say that all non-checked-out files are up
1106 <h2 id="_raw_output_format
">Raw output format</h2>
1107 <div class="sectionbody
">
1108 <div class="paragraph
"><p>The raw output format from "git-diff-index
", "git-diff-tree
",
1109 "git-diff-files
" and "git diff --raw
" are very similar.</p></div>
1110 <div class="paragraph
"><p>These commands all compare two sets of things; what is
1111 compared differs:</p></div>
1112 <div class="dlist
"><dl>
1113 <dt class="hdlist1
">
1114 git-diff-index <tree-ish>
1118 compares the <tree-ish> and the files on the filesystem.
1121 <dt class="hdlist1
">
1122 git-diff-index --cached <tree-ish>
1126 compares the <tree-ish> and the index.
1129 <dt class="hdlist1
">
1130 git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>…]
1134 compares the trees named by the two arguments.
1137 <dt class="hdlist1
">
1138 git-diff-files [<pattern>…]
1142 compares the index and the files on the filesystem.
1146 <div class="paragraph
"><p>The "git-diff-tree
" command begins its output by printing the hash of
1147 what is being compared. After that, all the commands print one output
1148 line per changed file.</p></div>
1149 <div class="paragraph
"><p>An output line is formatted this way:</p></div>
1150 <div class="listingblock
">
1151 <div class="content
">
1152 <pre><tt>in-place edit :100644 100644 bcd1234... 0123456... M file0
1153 copy-edit :100644 100644 abcd123... 1234567... C68 file1 file2
1154 rename-edit :100644 100644 abcd123... 1234567... R86 file1 file3
1155 create :000000 100644 0000000... 1234567... A file4
1156 delete :100644 000000 1234567... 0000000... D file5
1157 unmerged :000000 000000 0000000... 0000000... U file6</tt></pre>
1159 <div class="paragraph
"><p>That is, from the left to the right:</p></div>
1160 <div class="olist arabic
"><ol class="arabic
">
1168 mode for "src
"; 000000 if creation or unmerged.
1178 mode for "dst
"; 000000 if deletion or unmerged.
1188 sha1 for "src
"; 0{40} if creation or unmerged.
1198 sha1 for "dst
"; 0{40} if creation, unmerged or "look at work tree
".
1208 status, followed by optional "score
" number.
1213 a tab or a NUL when <em>-z</em> option is used.
1223 a tab or a NUL when <em>-z</em> option is used; only exists for C or R.
1228 path for "dst
"; only exists for C or R.
1233 an LF or a NUL when <em>-z</em> option is used, to terminate the record.
1237 <div class="paragraph
"><p>Possible status letters are:</p></div>
1238 <div class="ulist
"><ul>
1241 A: addition of a file
1246 C: copy of a file into a new one
1251 D: deletion of a file
1256 M: modification of the contents or mode of a file
1261 R: renaming of a file
1266 T: change in the type of the file
1271 U: file is unmerged (you must complete the merge before it can
1277 X: "unknown
" change type (most probably a bug, please report it)
1281 <div class="paragraph
"><p>Status letters C and R are always followed by a score (denoting the
1282 percentage of similarity between the source and target of the move or
1283 copy), and are the only ones to be so.</p></div>
1284 <div class="paragraph
"><p><sha1> is shown as all 0’s if a file is new on the filesystem
1285 and it is out of sync with the index.</p></div>
1286 <div class="paragraph
"><p>Example:</p></div>
1287 <div class="listingblock
">
1288 <div class="content
">
1289 <pre><tt>:100644 100644 5be4a4...... 000000...... M file.c</tt></pre>
1291 <div class="paragraph
"><p>When <tt>-z</tt> option is not used, TAB, LF, and backslash characters
1292 in pathnames are represented as <tt>\t</tt>, <tt>\n</tt>, and <tt>\\</tt>,
1293 respectively.</p></div>
1295 <h2 id="_diff_format_for_merges
">diff format for merges</h2>
1296 <div class="sectionbody
">
1297 <div class="paragraph
"><p>"git-diff-tree
", "git-diff-files
" and "git-diff --raw
"
1298 can take <em>-c</em> or <em>--cc</em> option
1299 to generate diff output also for merge commits. The output differs
1300 from the format described above in the following way:</p></div>
1301 <div class="olist arabic
"><ol class="arabic
">
1304 there is a colon for each parent
1309 there are more "src
" modes and "src
" sha1
1314 status is concatenated status characters for each parent
1319 no optional "score
" number
1324 single path, only for "dst
"
1328 <div class="paragraph
"><p>Example:</p></div>
1329 <div class="listingblock
">
1330 <div class="content
">
1331 <pre><tt>::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM describe.c</tt></pre>
1333 <div class="paragraph
"><p>Note that <em>combined diff</em> lists only files which were modified from
1334 all parents.</p></div>
1336 <h2 id="_generating_patches_with_p
">Generating patches with -p</h2>
1337 <div class="sectionbody
">
1338 <div class="paragraph
"><p>When "git-diff-index
", "git-diff-tree
", or "git-diff-files
" are run
1339 with a <em>-p</em> option, "git diff
" without the <em>--raw</em> option, or
1340 "git log
" with the "-p
" option, they
1341 do not produce the output described above; instead they produce a
1342 patch file. You can customize the creation of such patches via the
1343 GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables.</p></div>
1344 <div class="paragraph
"><p>What the -p option produces is slightly different from the traditional
1345 diff format:</p></div>
1346 <div class="olist arabic
"><ol class="arabic
">
1349 It is preceded with a "git diff
" header that looks like this:
1351 <div class="literalblock
">
1352 <div class="content
">
1353 <pre><tt>diff --git a/file1 b/file2</tt></pre>
1355 <div class="paragraph
"><p>The <tt>a/</tt> and <tt>b/</tt> filenames are the same unless rename/copy is
1356 involved. Especially, even for a creation or a deletion,
1357 <tt>/dev/null</tt> is <em>not</em> used in place of the <tt>a/</tt> or <tt>b/</tt> filenames.</p></div>
1358 <div class="paragraph
"><p>When rename/copy is involved, <tt>file1</tt> and <tt>file2</tt> show the
1359 name of the source file of the rename/copy and the name of
1360 the file that rename/copy produces, respectively.</p></div>
1364 It is followed by one or more extended header lines:
1366 <div class="literalblock
">
1367 <div class="content
">
1368 <pre><tt>old mode <mode>
1369 new mode <mode>
1370 deleted file mode <mode>
1371 new file mode <mode>
1372 copy from <path>
1373 copy to <path>
1374 rename from <path>
1375 rename to <path>
1376 similarity index <number>
1377 dissimilarity index <number>
1378 index <hash>..<hash> <mode></tt></pre>
1380 <div class="paragraph
"><p>File modes are printed as 6-digit octal numbers including the file type
1381 and file permission bits.</p></div>
1382 <div class="paragraph
"><p>Path names in extended headers do not include the <tt>a/</tt> and <tt>b/</tt> prefixes.</p></div>
1383 <div class="paragraph
"><p>The similarity index is the percentage of unchanged lines, and
1384 the dissimilarity index is the percentage of changed lines. It
1385 is a rounded down integer, followed by a percent sign. The
1386 similarity index value of 100% is thus reserved for two equal
1387 files, while 100% dissimilarity means that no line from the old
1388 file made it into the new one.</p></div>
1389 <div class="paragraph
"><p>The index line includes the SHA-1 checksum before and after the change.
1390 The <mode> is included if the file mode does not change; otherwise,
1391 separate lines indicate the old and the new mode.</p></div>
1395 TAB, LF, double quote and backslash characters in pathnames
1396 are represented as <tt>\t</tt>, <tt>\n</tt>, <tt>\"</tt> and
<tt>\\
</tt>, respectively.
1397 If there is need for such substitution then the whole
1398 pathname is put in double quotes.
1403 All the
<tt>file1
</tt> files in the output refer to files before the
1404 commit, and all the
<tt>file2
</tt> files refer to files after the commit.
1405 It is incorrect to apply each change to each file sequentially. For
1406 example, this patch will swap a and b:
1408 <div class=
"literalblock">
1409 <div class=
"content">
1410 <pre><tt>diff --git a/a b/b
1415 rename to a
</tt></pre>
1420 <h2 id=
"_combined_diff_format">combined diff format
</h2>
1421 <div class=
"sectionbody">
1422 <div class=
"paragraph"><p>Any diff-generating command can take the
‘-c` or
<tt>--cc
</tt> option to
1423 produce a
<em>combined diff
</em> when showing a merge. This is the default
1424 format when showing merges with
<a href=
"git-diff.html">git-diff(
1)
</a> or
1425 <a href=
"git-show.html">git-show(
1)
</a>. Note also that you can give the `-m
’ option to any
1426 of these commands to force generation of diffs with individual parents
1427 of a merge.
</p></div>
1428 <div class=
"paragraph"><p>A
<em>combined diff
</em> format looks like this:
</p></div>
1429 <div class=
"listingblock">
1430 <div class=
"content">
1431 <pre><tt>diff --combined describe.c
1432 index fabadb8,cc95eb0.
.4866510
1435 @@@ -
98,
20 -
98,
12 +
98,
20 @@@
1436 return (a_date
> b_date) ? -
1 : (a_date == b_date) ?
0 :
1;
1439 - static void describe(char *arg)
1440 -static void describe(struct commit *cmit, int last_one)
1441 ++static void describe(char *arg, int last_one)
1443 + unsigned char sha1[
20];
1444 + struct commit *cmit;
1445 struct commit_list *list;
1446 static int initialized =
0;
1447 struct commit_name *n;
1449 + if (get_sha1(arg, sha1)
< 0)
1450 + usage(describe_usage);
1451 + cmit = lookup_commit_reference(sha1);
1453 + usage(describe_usage);
1457 for_each_ref(get_name);
</tt></pre>
1459 <div class=
"olist arabic"><ol class=
"arabic">
1462 It is preceded with a
"git diff" header, that looks like
1463 this (when
<em>-c
</em> option is used):
1465 <div class=
"literalblock">
1466 <div class=
"content">
1467 <pre><tt>diff --combined file
</tt></pre>
1469 <div class=
"paragraph"><p>or like this (when
<em>--cc
</em> option is used):
</p></div>
1470 <div class=
"literalblock">
1471 <div class=
"content">
1472 <pre><tt>diff --cc file
</tt></pre>
1477 It is followed by one or more extended header lines
1478 (this example shows a merge with two parents):
1480 <div class=
"literalblock">
1481 <div class=
"content">
1482 <pre><tt>index
<hash
>,
<hash
>..
<hash
>
1483 mode
<mode
>,
<mode
>..
<mode
>
1484 new file mode
<mode
>
1485 deleted file mode
<mode
>,
<mode
></tt></pre>
1487 <div class=
"paragraph"><p>The
<tt>mode
<mode
>,
<mode
>..
<mode
></tt> line appears only if at least one of
1488 the
<mode
> is different from the rest. Extended headers with
1489 information about detected contents movement (renames and
1490 copying detection) are designed to work with diff of two
1491 <tree-ish
> and are not used by combined diff format.
</p></div>
1495 It is followed by two-line from-file/to-file header
1497 <div class=
"literalblock">
1498 <div class=
"content">
1500 +++ b/file
</tt></pre>
1502 <div class=
"paragraph"><p>Similar to two-line header for traditional
<em>unified
</em> diff
1503 format,
<tt>/dev/null
</tt> is used to signal created or deleted
1508 Chunk header format is modified to prevent people from
1509 accidentally feeding it to
<tt>patch -p1
</tt>. Combined diff format
1510 was created for review of merge commit changes, and was not
1511 meant for apply. The change is similar to the change in the
1512 extended
<em>index
</em> header:
1514 <div class=
"literalblock">
1515 <div class=
"content">
1516 <pre><tt>@@@
<from-file-range
> <from-file-range
> <to-file-range
> @@@
</tt></pre>
1518 <div class=
"paragraph"><p>There are (number of parents +
1)
<tt>@
</tt> characters in the chunk
1519 header for combined diff format.
</p></div>
1522 <div class=
"paragraph"><p>Unlike the traditional
<em>unified
</em> diff format, which shows two
1523 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
1524 added to B), or
<tt>" "</tt> (space
 — unchanged) prefix, this format
1525 compares two or more files file1, file2,
… with one file X, and
1526 shows how X differs from each of fileN. One column for each of
1527 fileN is prepended to the output line to note how X
’s line is
1528 different from it.
</p></div>
1529 <div class=
"paragraph"><p>A
<tt>-
</tt> character in the column N means that the line appears in
1530 fileN but it does not appear in the result. A
<tt>+
</tt> character
1531 in the column N means that the line appears in the result,
1532 and fileN does not have that line (in other words, the line was
1533 added, from the point of view of that parent).
</p></div>
1534 <div class=
"paragraph"><p>In the above example output, the function signature was changed
1535 from both files (hence two
<tt>-
</tt> removals from both file1 and
1536 file2, plus
<tt>++
</tt> to mean one line that was added does not appear
1537 in either file1 nor file2). Also eight other lines are the same
1538 from file1 but do not appear in file2 (hence prefixed with
<tt>+</tt>).
</p></div>
1539 <div class=
"paragraph"><p>When shown by
<tt>git diff-tree -c
</tt>, it compares the parents of a
1540 merge commit with the merge result (i.e. file1..fileN are the
1541 parents). When shown by
<tt>git diff-files -c
</tt>, it compares the
1542 two unresolved merge parents with the working tree file
1543 (i.e. file1 is stage
2 aka
"our version", file2 is stage
3 aka
1544 "their version").
</p></div>
1546 <h2 id=
"_other_diff_formats">other diff formats
</h2>
1547 <div class=
"sectionbody">
1548 <div class=
"paragraph"><p>The
<tt>--summary
</tt> option describes newly added, deleted, renamed and
1549 copied files. The
<tt>--stat
</tt> option adds diffstat(
1) graph to the
1550 output. These options can be combined with other options, such as
1551 <tt>-p
</tt>, and are meant for human consumption.
</p></div>
1552 <div class=
"paragraph"><p>When showing a change that involves a rename or a copy,
<tt>--stat
</tt> output
1553 formats the pathnames compactly by combining common prefix and suffix of
1554 the pathnames. For example, a change that moves
<tt>arch/i386/Makefile
</tt> to
1555 <tt>arch/x86/Makefile
</tt> while modifying
4 lines will be shown like this:
</p></div>
1556 <div class=
"listingblock">
1557 <div class=
"content">
1558 <pre><tt>arch/{i386 =
> x86}/Makefile |
4 +--
</tt></pre>
1560 <div class=
"paragraph"><p>The
<tt>--numstat
</tt> option gives the diffstat(
1) information but is designed
1561 for easier machine consumption. An entry in
<tt>--numstat
</tt> output looks
1562 like this:
</p></div>
1563 <div class=
"listingblock">
1564 <div class=
"content">
1566 3 1 arch/{i386 =
> x86}/Makefile
</tt></pre>
1568 <div class=
"paragraph"><p>That is, from left to right:
</p></div>
1569 <div class=
"olist arabic"><ol class=
"arabic">
1572 the number of added lines;
1582 the number of deleted lines;
1592 pathname (possibly with rename/copy information);
1601 <div class=
"paragraph"><p>When
<tt>-z
</tt> output option is in effect, the output is formatted this way:
</p></div>
1602 <div class=
"listingblock">
1603 <div class=
"content">
1604 <pre><tt>1 2 README NUL
1605 3 1 NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
</tt></pre>
1607 <div class=
"paragraph"><p>That is:
</p></div>
1608 <div class=
"olist arabic"><ol class=
"arabic">
1611 the number of added lines;
1621 the number of deleted lines;
1631 a NUL (only exists if renamed/copied);
1636 pathname in preimage;
1641 a NUL (only exists if renamed/copied);
1646 pathname in postimage (only exists if renamed/copied);
1655 <div class=
"paragraph"><p>The extra
<tt>NUL
</tt> before the preimage path in renamed case is to allow
1656 scripts that read the output to tell if the current record being read is
1657 a single-path record or a rename/copy record without reading ahead.
1658 After reading added and deleted lines, reading up to
<tt>NUL
</tt> would yield
1659 the pathname, but if that is
<tt>NUL
</tt>, the record will show two paths.
</p></div>
1661 <h2 id=
"_operating_modes">Operating Modes
</h2>
1662 <div class=
"sectionbody">
1663 <div class=
"paragraph"><p>You can choose whether you want to trust the index file entirely
1664 (using the
<em>--cached
</em> flag) or ask the diff logic to show any files
1665 that don
’t match the stat state as being
"tentatively changed". Both
1666 of these operations are very useful indeed.
</p></div>
1668 <h2 id=
"_cached_mode">Cached Mode
</h2>
1669 <div class=
"sectionbody">
1670 <div class=
"paragraph"><p>If
<em>--cached
</em> is specified, it allows you to ask:
</p></div>
1671 <div class=
"literalblock">
1672 <div class=
"content">
1673 <pre><tt>show me the differences between HEAD and the current index
1674 contents (the ones I'd write using 'git write-tree')
</tt></pre>
1676 <div class=
"paragraph"><p>For example, let
’s say that you have worked on your working directory, updated
1677 some files in the index and are ready to commit. You want to see exactly
1678 <strong>what
</strong> you are going to commit, without having to write a new tree
1679 object and compare it that way, and to do that, you just do
</p></div>
1680 <div class=
"literalblock">
1681 <div class=
"content">
1682 <pre><tt>git diff-index --cached HEAD
</tt></pre>
1684 <div class=
"paragraph"><p>Example: let
’s say I had renamed
<tt>commit.c
</tt> to
<tt>git-commit.c
</tt>, and I had
1685 done an
<tt>update-index
</tt> to make that effective in the index file.
1686 <tt>git diff-files
</tt> wouldn
’t show anything at all, since the index file
1687 matches my working directory. But doing a
<em>git diff-index
</em> does:
</p></div>
1688 <div class=
"literalblock">
1689 <div class=
"content">
1690 <pre><tt>torvalds@ppc970:~/git
> git diff-index --cached HEAD
1691 -
100644 blob
4161aecc6700a2eb579e842af0b7f22b98443f74 commit.c
1692 +
100644 blob
4161aecc6700a2eb579e842af0b7f22b98443f74 git-commit.c
</tt></pre>
1694 <div class=
"paragraph"><p>You can see easily that the above is a rename.
</p></div>
1695 <div class=
"paragraph"><p>In fact,
<tt>git diff-index --cached
</tt> <strong>should
</strong> always be entirely equivalent to
1696 actually doing a
<em>git write-tree
</em> and comparing that. Except this one is much
1697 nicer for the case where you just want to check where you are.
</p></div>
1698 <div class=
"paragraph"><p>So doing a
<tt>git diff-index --cached
</tt> is basically very useful when you are
1699 asking yourself
"what have I already marked for being committed, and
1700 what’s the difference to a previous tree".
</p></div>
1702 <h2 id=
"_non_cached_mode">Non-cached Mode
</h2>
1703 <div class=
"sectionbody">
1704 <div class=
"paragraph"><p>The
"non-cached" mode takes a different approach, and is potentially
1705 the more useful of the two in that what it does can
’t be emulated with
1706 a
<em>git write-tree
</em> +
<em>git diff-tree
</em>. Thus that
’s the default mode.
1707 The non-cached version asks the question:
</p></div>
1708 <div class=
"literalblock">
1709 <div class=
"content">
1710 <pre><tt>show me the differences between HEAD and the currently checked out
1711 tree - index contents _and_ files that aren't up-to-date
</tt></pre>
1713 <div class=
"paragraph"><p>which is obviously a very useful question too, since that tells you what
1714 you
<strong>could
</strong> commit. Again, the output matches the
<em>git diff-tree -r
</em>
1715 output to a tee, but with a twist.
</p></div>
1716 <div class=
"paragraph"><p>The twist is that if some file doesn
’t match the index, we don
’t have
1717 a backing store thing for it, and we use the magic
"all-zero" sha1 to
1718 show that. So let
’s say that you have edited
<tt>kernel/sched.c
</tt>, but
1719 have not actually done a
<em>git update-index
</em> on it yet - there is no
1720 "object" associated with the new state, and you get:
</p></div>
1721 <div class=
"literalblock">
1722 <div class=
"content">
1723 <pre><tt>torvalds@ppc970:~/v2.6/linux
> git diff-index HEAD
1724 *
100644-
>100664 blob
7476bb......-
>000000...... kernel/sched.c
</tt></pre>
1726 <div class=
"paragraph"><p>i.e., it shows that the tree has changed, and that
<tt>kernel/sched.c
</tt> has is
1727 not up-to-date and may contain new stuff. The all-zero sha1 means that to
1728 get the real diff, you need to look at the object in the working directory
1729 directly rather than do an object-to-object diff.
</p></div>
1730 <div class=
"admonitionblock">
1733 <div class=
"title">Note
</div>
1735 <td class=
"content">As with other commands of this type,
<em>git diff-index
</em> does not
1736 actually look at the contents of the file at all. So maybe
1737 <tt>kernel/sched.c
</tt> hasn
’t actually changed, and it
’s just that you
1738 touched it. In either case, it
’s a note that you need to
1739 <em>git update-index
</em> it to make the index be in sync.
</td>
1742 <div class=
"admonitionblock">
1745 <div class=
"title">Note
</div>
1747 <td class=
"content">You can have a mixture of files show up as
"has been updated"
1748 and
"is still dirty in the working directory" together. You can always
1749 tell which file is in which state, since the
"has been updated" ones
1750 show a valid sha1, and the
"not in sync with the index" ones will
1751 always have the special all-zero sha1.
</td>
1755 <h2 id=
"_git">GIT
</h2>
1756 <div class=
"sectionbody">
1757 <div class=
"paragraph"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
1760 <div id=
"footer-text">
1761 Last updated
2011-
03-
15 23:
30:
13 UTC