<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

<article lang="en" id="git-diff-index(1)">
<articleinfo>
    <title>git-diff-index(1)</title>
        <indexterm>
                <primary>git-diff-index(1)</primary>
        </indexterm>
</articleinfo>
<simplesect id="_name">
<title>NAME</title>
<simpara>git-diff-index - Compares content and mode of blobs between the index and repository</simpara>
</simplesect>
<simplesect id="_synopsis">
<title>SYNOPSIS</title>
<simpara><emphasis>git diff-index</emphasis> [-m] [--cached] [&lt;common diff options&gt;] &lt;tree-ish&gt; [&lt;path&gt;&#8230;]</simpara>
</simplesect>
<simplesect id="_description">
<title>DESCRIPTION</title>
<simpara>Compares the content and mode of the blobs found via a tree
object with the content of the current index and, optionally
ignoring the stat state of the file on disk.  When paths are
specified, compares only those named paths.  Otherwise all
entries in the index are compared.</simpara>
</simplesect>
<simplesect id="_options">
<title>OPTIONS</title>
<variablelist>
<varlistentry>
<term>
-p
</term>
<term>
-u
</term>
<listitem>
<simpara>
        Generate patch (see section on generating patches).
        
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-U&lt;n&gt;
</term>
<term>
--unified=&lt;n&gt;
</term>
<listitem>
<simpara>
        Generate diffs with &lt;n&gt; lines of context instead of
        the usual three. Implies "-p".
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--raw
</term>
<listitem>
<simpara>
        Generate the raw format.
         This is the default.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--patch-with-raw
</term>
<listitem>
<simpara>
        Synonym for "-p --raw".
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--patience
</term>
<listitem>
<simpara>
        Generate a diff using the "patience diff" algorithm.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--stat[=width[,name-width]]
</term>
<listitem>
<simpara>
        Generate a diffstat.  You can override the default
        output width for 80-column terminal by "--stat=width".
        The width of the filename part can be controlled by
        giving another width to it separated by a comma.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--numstat
</term>
<listitem>
<simpara>
        Similar to --stat, but shows number of added and
        deleted lines in decimal notation and pathname without
        abbreviation, to make it more machine friendly.  For
        binary files, outputs two <literal>-</literal> instead of saying
        <literal>0 0</literal>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--shortstat
</term>
<listitem>
<simpara>
        Output only the last line of the --stat format containing total
        number of modified files, as well as number of added and deleted
        lines.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--dirstat[=limit]
</term>
<listitem>
<simpara>
        Output the distribution of relative amount of changes (number of lines added or
        removed) for each sub-directory. Directories with changes below
        a cut-off percent (3% by default) are not shown. The cut-off percent
        can be set with "--dirstat=limit". Changes in a child directory is not
        counted for the parent directory, unless "--cumulative" is used.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--dirstat-by-file[=limit]
</term>
<listitem>
<simpara>
        Same as --dirstat, but counts changed files instead of lines.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--summary
</term>
<listitem>
<simpara>
        Output a condensed summary of extended header information
        such as creations, renames and mode changes.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--patch-with-stat
</term>
<listitem>
<simpara>
        Synonym for "-p --stat".
        
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-z
</term>
<listitem>
<simpara>
        NUL-line termination on output.  This affects the --raw
        output field terminator.  Also output from commands such
        as "git-log" will be delimited with NUL between commits.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--name-only
</term>
<listitem>
<simpara>
        Show only names of changed files.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--name-status
</term>
<listitem>
<simpara>
        Show only names and status of changed files. See the description
        of the <literal>--diff-filter</literal> option on what the status letters mean.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--color
</term>
<listitem>
<simpara>
        Show colored diff.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--no-color
</term>
<listitem>
<simpara>
        Turn off colored diff, even when the configuration file
        gives the default to color output.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--color-words[=&lt;regex&gt;]
</term>
<listitem>
<simpara>
        Show colored word diff, i.e., color words which have changed.
        By default, words are separated by whitespace.
</simpara>
<simpara>When a &lt;regex&gt; is specified, every non-overlapping match of the
&lt;regex&gt; is considered a word.  Anything between these matches is
considered whitespace and ignored(!) for the purposes of finding
differences.  You may want to append <literal>|[^[:space:]]</literal> to your regular
expression to make sure that it matches all non-whitespace characters.
A match that contains a newline is silently truncated(!) at the
newline.</simpara>
<simpara>The regex can also be set via a diff driver or configuration option, see
<xref linkend="gitattributes(1)"/> or <xref linkend="git-config(1)"/>.  Giving it explicitly
overrides any diff driver or configuration setting.  Diff drivers
override configuration settings.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--no-renames
</term>
<listitem>
<simpara>
        Turn off rename detection, even when the configuration
        file gives the default to do so.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--check
</term>
<listitem>
<simpara>
        Warn if changes introduce trailing whitespace
        or an indent that uses a space before a tab. Exits with
        non-zero status if problems are found. Not compatible with
        --exit-code.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--full-index
</term>
<listitem>
<simpara>
        Instead of the first handful of characters, show the full
        pre- and post-image blob object names on the "index"
        line when generating patch format output.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--binary
</term>
<listitem>
<simpara>
        In addition to --full-index, output "binary diff" that
        can be applied with "git apply".
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--abbrev[=&lt;n&gt;]
</term>
<listitem>
<simpara>
        Instead of showing the full 40-byte hexadecimal object
        name in diff-raw format output and diff-tree header
        lines, show only a partial prefix.  This is
        independent of --full-index option above, which controls
        the diff-patch output format.  Non default number of
        digits can be specified with --abbrev=&lt;n&gt;.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-B
</term>
<listitem>
<simpara>
        Break complete rewrite changes into pairs of delete and create.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-M
</term>
<listitem>
<simpara>
        Detect renames.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-C
</term>
<listitem>
<simpara>
        Detect copies as well as renames.  See also <literal>--find-copies-harder</literal>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--diff-filter=[ACDMRTUXB*]
</term>
<listitem>
<simpara>
        Select only files that are Added (<literal>A</literal>), Copied (<literal>C</literal>),
        Deleted (<literal>D</literal>), Modified (<literal>M</literal>), Renamed (<literal>R</literal>), have their
        type (i.e. regular file, symlink, submodule, &#8230;) changed (<literal>T</literal>),
        are Unmerged (<literal>U</literal>), are
        Unknown (<literal>X</literal>), or have had their pairing Broken (<literal>B</literal>).
        Any combination of the filter characters may be used.
        When <literal>*</literal> (All-or-none) is added to the combination, all
        paths are selected if there is any file that matches
        other criteria in the comparison; if there is no file
        that matches other criteria, nothing is selected.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--find-copies-harder
</term>
<listitem>
<simpara>
        For performance reasons, by default, <literal>-C</literal> option finds copies only
        if the original file of the copy was modified in the same
        changeset.  This flag makes the command
        inspect unmodified files as candidates for the source of
        copy.  This is a very expensive operation for large
        projects, so use it with caution.  Giving more than one
        <literal>-C</literal> option has the same effect.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-l&lt;num&gt;
</term>
<listitem>
<simpara>
        -M and -C options require O(n^2) processing time where n
        is the number of potential rename/copy targets.  This
        option prevents rename/copy detection from running if
        the number of rename/copy targets exceeds the specified
        number.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-S&lt;string&gt;
</term>
<listitem>
<simpara>
        Look for differences that contain the change in &lt;string&gt;.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--pickaxe-all
</term>
<listitem>
<simpara>
        When -S finds a change, show all the changes in that
        changeset, not just the files that contain the change
        in &lt;string&gt;.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--pickaxe-regex
</term>
<listitem>
<simpara>
        Make the &lt;string&gt; not a plain string but an extended POSIX
        regex to match.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-O&lt;orderfile&gt;
</term>
<listitem>
<simpara>
        Output the patch in the order specified in the
        &lt;orderfile&gt;, which has one shell glob pattern per line.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-R
</term>
<listitem>
<simpara>
        Swap two inputs; that is, show differences from index or
        on-disk file to tree contents.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--relative[=&lt;path&gt;]
</term>
<listitem>
<simpara>
        When run from a subdirectory of the project, it can be
        told to exclude changes outside the directory and show
        pathnames relative to it with this option.  When you are
        not in a subdirectory (e.g. in a bare repository), you
        can name which subdirectory to make the output relative
        to by giving a &lt;path&gt; as an argument.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-a
</term>
<term>
--text
</term>
<listitem>
<simpara>
        Treat all files as text.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--ignore-space-at-eol
</term>
<listitem>
<simpara>
        Ignore changes in whitespace at EOL.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-b
</term>
<term>
--ignore-space-change
</term>
<listitem>
<simpara>
        Ignore changes in amount of whitespace.  This ignores whitespace
        at line end, and considers all other sequences of one or
        more whitespace characters to be equivalent.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-w
</term>
<term>
--ignore-all-space
</term>
<listitem>
<simpara>
        Ignore whitespace when comparing lines.  This ignores
        differences even if one line has whitespace where the other
        line has none.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--inter-hunk-context=&lt;lines&gt;
</term>
<listitem>
<simpara>
        Show the context between diff hunks, up to the specified number
        of lines, thereby fusing hunks that are close to each other.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--exit-code
</term>
<listitem>
<simpara>
        Make the program exit with codes similar to diff(1).
        That is, it exits with 1 if there were differences and
        0 means no differences.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--quiet
</term>
<listitem>
<simpara>
        Disable all output of the program. Implies --exit-code.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--ext-diff
</term>
<listitem>
<simpara>
        Allow an external diff helper to be executed. If you set an
        external diff driver with <xref linkend="gitattributes(5)"/>, you need
        to use this option with <xref linkend="git-log(1)"/> and friends.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--no-ext-diff
</term>
<listitem>
<simpara>
        Disallow external diff drivers.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--ignore-submodules
</term>
<listitem>
<simpara>
        Ignore changes to submodules in the diff generation.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--src-prefix=&lt;prefix&gt;
</term>
<listitem>
<simpara>
        Show the given source prefix instead of "a/".
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--dst-prefix=&lt;prefix&gt;
</term>
<listitem>
<simpara>
        Show the given destination prefix instead of "b/".
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--no-prefix
</term>
<listitem>
<simpara>
        Do not show any source or destination prefix.
</simpara>
</listitem>
</varlistentry>
</variablelist>
<simpara>For more detailed explanation on these common options, see also
<xref linkend="gitdiffcore(7)"/>.</simpara>
<variablelist>
<varlistentry>
<term>
&lt;tree-ish&gt;
</term>
<listitem>
<simpara>
        The id of a tree object to diff against.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--cached
</term>
<listitem>
<simpara>
        do not consider the on-disk file at all
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-m
</term>
<listitem>
<simpara>
        By default, files recorded in the index but not checked
        out are reported as deleted.  This flag makes
        <emphasis>git-diff-index</emphasis> say that all non-checked-out files are up
        to date.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="_output_format">
<title>Output format</title>
<simpara>The output format from "git-diff-index", "git-diff-tree",
"git-diff-files" and "git diff --raw" are very similar.</simpara>
<simpara>These commands all compare two sets of things; what is
compared differs:</simpara>
<variablelist>
<varlistentry>
<term>
git-diff-index &lt;tree-ish&gt;
</term>
<listitem>
<simpara>
        compares the &lt;tree-ish&gt; and the files on the filesystem.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
git-diff-index --cached &lt;tree-ish&gt;
</term>
<listitem>
<simpara>
        compares the &lt;tree-ish&gt; and the index.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
git-diff-tree [-r] &lt;tree-ish-1&gt; &lt;tree-ish-2&gt; [&lt;pattern&gt;&#8230;]
</term>
<listitem>
<simpara>
        compares the trees named by the two arguments.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
git-diff-files [&lt;pattern&gt;&#8230;]
</term>
<listitem>
<simpara>
        compares the index and the files on the filesystem.
</simpara>
</listitem>
</varlistentry>
</variablelist>
<simpara>An output line is formatted this way:</simpara>
<literallayout>in-place edit  :100644 100644 bcd1234... 0123456... M file0
copy-edit      :100644 100644 abcd123... 1234567... C68 file1 file2
rename-edit    :100644 100644 abcd123... 1234567... R86 file1 file3
create         :000000 100644 0000000... 1234567... A file4
delete         :100644 000000 1234567... 0000000... D file5
unmerged       :000000 000000 0000000... 0000000... U file6</literallayout>
<simpara>That is, from the left to the right:</simpara>
<orderedlist numeration="arabic">
<listitem>
<simpara>
a colon.
</simpara>
</listitem>
<listitem>
<simpara>
mode for "src"; 000000 if creation or unmerged.
</simpara>
</listitem>
<listitem>
<simpara>
a space.
</simpara>
</listitem>
<listitem>
<simpara>
mode for "dst"; 000000 if deletion or unmerged.
</simpara>
</listitem>
<listitem>
<simpara>
a space.
</simpara>
</listitem>
<listitem>
<simpara>
sha1 for "src"; 0{40} if creation or unmerged.
</simpara>
</listitem>
<listitem>
<simpara>
a space.
</simpara>
</listitem>
<listitem>
<simpara>
sha1 for "dst"; 0{40} if creation, unmerged or "look at work tree".
</simpara>
</listitem>
<listitem>
<simpara>
a space.
</simpara>
</listitem>
<listitem>
<simpara>
status, followed by optional "score" number.
</simpara>
</listitem>
<listitem>
<simpara>
a tab or a NUL when <emphasis>-z</emphasis> option is used.
</simpara>
</listitem>
<listitem>
<simpara>
path for "src"
</simpara>
</listitem>
<listitem>
<simpara>
a tab or a NUL when <emphasis>-z</emphasis> option is used; only exists for C or R.
</simpara>
</listitem>
<listitem>
<simpara>
path for "dst"; only exists for C or R.
</simpara>
</listitem>
<listitem>
<simpara>
an LF or a NUL when <emphasis>-z</emphasis> option is used, to terminate the record.
</simpara>
</listitem>
</orderedlist>
<simpara>Possible status letters are:</simpara>
<itemizedlist>
<listitem>
<simpara>
A: addition of a file
</simpara>
</listitem>
<listitem>
<simpara>
C: copy of a file into a new one
</simpara>
</listitem>
<listitem>
<simpara>
D: deletion of a file
</simpara>
</listitem>
<listitem>
<simpara>
M: modification of the contents or mode of a file
</simpara>
</listitem>
<listitem>
<simpara>
R: renaming of a file
</simpara>
</listitem>
<listitem>
<simpara>
T: change in the type of the file
</simpara>
</listitem>
<listitem>
<simpara>
U: file is unmerged (you must complete the merge before it can
be committed)
</simpara>
</listitem>
<listitem>
<simpara>
X: "unknown" change type (most probably a bug, please report it)
</simpara>
</listitem>
</itemizedlist>
<simpara>Status letters C and R are always followed by a score (denoting the
percentage of similarity between the source and target of the move or
copy), and are the only ones to be so.</simpara>
<simpara>&lt;sha1&gt; is shown as all 0&#8217;s if a file is new on the filesystem
and it is out of sync with the index.</simpara>
<simpara>Example:</simpara>
<literallayout>:100644 100644 5be4a4...... 000000...... M file.c</literallayout>
<simpara>When <literal>-z</literal> option is not used, TAB, LF, and backslash characters
in pathnames are represented as <literal>\t</literal>, <literal>\n</literal>, and <literal>\\</literal>,
respectively.</simpara>
</simplesect>
<simplesect id="_diff_format_for_merges">
<title>diff format for merges</title>
<simpara>"git-diff-tree", "git-diff-files" and "git-diff --raw"
can take <emphasis>-c</emphasis> or <emphasis>--cc</emphasis> option
to generate diff output also for merge commits.  The output differs
from the format described above in the following way:</simpara>
<orderedlist numeration="arabic">
<listitem>
<simpara>
there is a colon for each parent
</simpara>
</listitem>
<listitem>
<simpara>
there are more "src" modes and "src" sha1
</simpara>
</listitem>
<listitem>
<simpara>
status is concatenated status characters for each parent
</simpara>
</listitem>
<listitem>
<simpara>
no optional "score" number
</simpara>
</listitem>
<listitem>
<simpara>
single path, only for "dst"
</simpara>
</listitem>
</orderedlist>
<simpara>Example:</simpara>
<literallayout>::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM      describe.c</literallayout>
<simpara>Note that <emphasis>combined diff</emphasis> lists only files which were modified from
all parents.</simpara>
</simplesect>
<simplesect id="_generating_patches_with_p">
<title>Generating patches with -p</title>
<simpara>When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
with a <emphasis>-p</emphasis> option, "git diff" without the <emphasis>--raw</emphasis> option, or
"git log" with the "-p" option, they
do not produce the output described above; instead they produce a
patch file.  You can customize the creation of such patches via the
GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables.</simpara>
<simpara>What the -p option produces is slightly different from the traditional
diff format.</simpara>
<orderedlist numeration="arabic">
<listitem>
<simpara>
It is preceded with a "git diff" header, that looks like
     this:
</simpara>
<literallayout class="monospaced">diff --git a/file1 b/file2</literallayout>
<simpara>The <literal>a/</literal> and <literal>b/</literal> filenames are the same unless rename/copy is
involved.  Especially, even for a creation or a deletion,
<literal>/dev/null</literal> is <emphasis>not</emphasis> used in place of <literal>a/</literal> or <literal>b/</literal> filenames.</simpara>
<simpara>When rename/copy is involved, <literal>file1</literal> and <literal>file2</literal> show the
name of the source file of the rename/copy and the name of
the file that rename/copy produces, respectively.</simpara>
</listitem>
<listitem>
<simpara>
It is followed by one or more extended header lines:
</simpara>
<literallayout class="monospaced">old mode &lt;mode&gt;
new mode &lt;mode&gt;
deleted file mode &lt;mode&gt;
new file mode &lt;mode&gt;
copy from &lt;path&gt;
copy to &lt;path&gt;
rename from &lt;path&gt;
rename to &lt;path&gt;
similarity index &lt;number&gt;
dissimilarity index &lt;number&gt;
index &lt;hash&gt;..&lt;hash&gt; &lt;mode&gt;</literallayout>
</listitem>
<listitem>
<simpara>
TAB, LF, double quote and backslash characters in pathnames
    are represented as <literal>\t</literal>, <literal>\n</literal>, <literal>\"</literal> and <literal>\\</literal>, respectively.
    If there is need for such substitution then the whole
    pathname is put in double quotes.
</simpara>
</listitem>
</orderedlist>
<simpara>The similarity index is the percentage of unchanged lines, and
the dissimilarity index is the percentage of changed lines.  It
is a rounded down integer, followed by a percent sign.  The
similarity index value of 100% is thus reserved for two equal
files, while 100% dissimilarity means that no line from the old
file made it into the new one.</simpara>
</simplesect>
<simplesect id="_combined_diff_format">
<title>combined diff format</title>
<simpara>"git-diff-tree", "git-diff-files" and "git-diff" can take <emphasis>-c</emphasis> or
<emphasis>--cc</emphasis> option to produce <emphasis>combined diff</emphasis>.  For showing a merge commit
with "git log -p", this is the default format.
A <emphasis>combined diff</emphasis> format looks like this:</simpara>
<literallayout>diff --combined describe.c
index fabadb8,cc95eb0..4866510
--- a/describe.c
+++ b/describe.c
@@@ -98,20 -98,12 +98,20 @@@
        return (a_date &gt; b_date) ? -1 : (a_date == b_date) ? 0 : 1;
  }

- static void describe(char *arg)
 -static void describe(struct commit *cmit, int last_one)
++static void describe(char *arg, int last_one)
  {
 +      unsigned char sha1[20];
 +      struct commit *cmit;
        struct commit_list *list;
        static int initialized = 0;
        struct commit_name *n;

 +      if (get_sha1(arg, sha1) &lt; 0)
 +              usage(describe_usage);
 +      cmit = lookup_commit_reference(sha1);
 +      if (!cmit)
 +              usage(describe_usage);
 +
        if (!initialized) {
                initialized = 1;
                for_each_ref(get_name);</literallayout>
<orderedlist numeration="arabic">
<listitem>
<simpara>
It is preceded with a "git diff" header, that looks like
     this (when <emphasis>-c</emphasis> option is used):
</simpara>
<literallayout class="monospaced">diff --combined file</literallayout>
<simpara>or like this (when <emphasis>--cc</emphasis> option is used):</simpara>
<literallayout class="monospaced">diff --cc file</literallayout>
</listitem>
<listitem>
<simpara>
It is followed by one or more extended header lines
     (this example shows a merge with two parents):
</simpara>
<literallayout class="monospaced">index &lt;hash&gt;,&lt;hash&gt;..&lt;hash&gt;
mode &lt;mode&gt;,&lt;mode&gt;..&lt;mode&gt;
new file mode &lt;mode&gt;
deleted file mode &lt;mode&gt;,&lt;mode&gt;</literallayout>
<simpara>The <literal>mode &lt;mode&gt;,&lt;mode&gt;..&lt;mode&gt;</literal> line appears only if at least one of
the &lt;mode&gt; is different from the rest. Extended headers with
information about detected contents movement (renames and
copying detection) are designed to work with diff of two
&lt;tree-ish&gt; and are not used by combined diff format.</simpara>
</listitem>
<listitem>
<simpara>
It is followed by two-line from-file/to-file header
</simpara>
<literallayout class="monospaced">--- a/file
+++ b/file</literallayout>
<simpara>Similar to two-line header for traditional <emphasis>unified</emphasis> diff
format, <literal>/dev/null</literal> is used to signal created or deleted
files.</simpara>
</listitem>
<listitem>
<simpara>
Chunk header format is modified to prevent people from
     accidentally feeding it to <literal>patch -p1</literal>. Combined diff format
     was created for review of merge commit changes, and was not
     meant for apply. The change is similar to the change in the
     extended <emphasis>index</emphasis> header:
</simpara>
<literallayout class="monospaced">@@@ &lt;from-file-range&gt; &lt;from-file-range&gt; &lt;to-file-range&gt; @@@</literallayout>
<simpara>There are (number of parents + 1) <literal>@</literal> characters in the chunk
header for combined diff format.</simpara>
</listitem>
</orderedlist>
<simpara>Unlike the traditional <emphasis>unified</emphasis> diff format, which shows two
files A and B with a single column that has <literal>-</literal> (minus&#8201;&#8212;&#8201;appears in A but removed in B), <literal>+</literal> (plus&#8201;&#8212;&#8201;missing in A but
added to B), or <literal>" "</literal> (space&#8201;&#8212;&#8201;unchanged) prefix, this format
compares two or more files file1, file2,&#8230; with one file X, and
shows how X differs from each of fileN.  One column for each of
fileN is prepended to the output line to note how X&#8217;s line is
different from it.</simpara>
<simpara>A <literal>-</literal> character in the column N means that the line appears in
fileN but it does not appear in the result.  A <literal>+</literal> character
in the column N means that the line appears in the result,
and fileN does not have that line (in other words, the line was
added, from the point of view of that parent).</simpara>
<simpara>In the above example output, the function signature was changed
from both files (hence two <literal>-</literal> removals from both file1 and
file2, plus <literal>++</literal> to mean one line that was added does not appear
in either file1 nor file2).  Also eight other lines are the same
from file1 but do not appear in file2 (hence prefixed with <literal>&#43;</literal>).</simpara>
<simpara>When shown by <literal>git diff-tree -c</literal>, it compares the parents of a
merge commit with the merge result (i.e. file1..fileN are the
parents).  When shown by <literal>git diff-files -c</literal>, it compares the
two unresolved merge parents with the working tree file
(i.e. file1 is stage 2 aka "our version", file2 is stage 3 aka
"their version").</simpara>
</simplesect>
<simplesect id="_other_diff_formats">
<title>other diff formats</title>
<simpara>The <literal>--summary</literal> option describes newly added, deleted, renamed and
copied files.  The <literal>--stat</literal> option adds diffstat(1) graph to the
output.  These options can be combined with other options, such as
<literal>-p</literal>, and are meant for human consumption.</simpara>
<simpara>When showing a change that involves a rename or a copy, <literal>--stat</literal> output
formats the pathnames compactly by combining common prefix and suffix of
the pathnames.  For example, a change that moves <literal>arch/i386/Makefile</literal> to
<literal>arch/x86/Makefile</literal> while modifying 4 lines will be shown like this:</simpara>
<literallayout>arch/{i386 =&gt; x86}/Makefile    |   4 +--</literallayout>
<simpara>The <literal>--numstat</literal> option gives the diffstat(1) information but is designed
for easier machine consumption.  An entry in <literal>--numstat</literal> output looks
like this:</simpara>
<literallayout>1       2       README
3       1       arch/{i386 =&gt; x86}/Makefile</literallayout>
<simpara>That is, from left to right:</simpara>
<orderedlist numeration="arabic">
<listitem>
<simpara>
the number of added lines;
</simpara>
</listitem>
<listitem>
<simpara>
a tab;
</simpara>
</listitem>
<listitem>
<simpara>
the number of deleted lines;
</simpara>
</listitem>
<listitem>
<simpara>
a tab;
</simpara>
</listitem>
<listitem>
<simpara>
pathname (possibly with rename/copy information);
</simpara>
</listitem>
<listitem>
<simpara>
a newline.
</simpara>
</listitem>
</orderedlist>
<simpara>When <literal>-z</literal> output option is in effect, the output is formatted this way:</simpara>
<literallayout>1       2       README NUL
3       1       NUL arch/i386/Makefile NUL arch/x86/Makefile NUL</literallayout>
<simpara>That is:</simpara>
<orderedlist numeration="arabic">
<listitem>
<simpara>
the number of added lines;
</simpara>
</listitem>
<listitem>
<simpara>
a tab;
</simpara>
</listitem>
<listitem>
<simpara>
the number of deleted lines;
</simpara>
</listitem>
<listitem>
<simpara>
a tab;
</simpara>
</listitem>
<listitem>
<simpara>
a NUL (only exists if renamed/copied);
</simpara>
</listitem>
<listitem>
<simpara>
pathname in preimage;
</simpara>
</listitem>
<listitem>
<simpara>
a NUL (only exists if renamed/copied);
</simpara>
</listitem>
<listitem>
<simpara>
pathname in postimage (only exists if renamed/copied);
</simpara>
</listitem>
<listitem>
<simpara>
a NUL.
</simpara>
</listitem>
</orderedlist>
<simpara>The extra <literal>NUL</literal> before the preimage path in renamed case is to allow
scripts that read the output to tell if the current record being read is
a single-path record or a rename/copy record without reading ahead.
After reading added and deleted lines, reading up to <literal>NUL</literal> would yield
the pathname, but if that is <literal>NUL</literal>, the record will show two paths.</simpara>
</simplesect>
<simplesect id="_operating_modes">
<title>Operating Modes</title>
<simpara>You can choose whether you want to trust the index file entirely
(using the <emphasis>--cached</emphasis> flag) or ask the diff logic to show any files
that don&#8217;t match the stat state as being "tentatively changed".  Both
of these operations are very useful indeed.</simpara>
</simplesect>
<simplesect id="_cached_mode">
<title>Cached Mode</title>
<simpara>If <emphasis>--cached</emphasis> is specified, it allows you to ask:</simpara>
<literallayout class="monospaced">show me the differences between HEAD and the current index
contents (the ones I'd write using 'git-write-tree')</literallayout>
<simpara>For example, let&#8217;s say that you have worked on your working directory, updated
some files in the index and are ready to commit. You want to see exactly
<emphasis role="strong">what</emphasis> you are going to commit, without having to write a new tree
object and compare it that way, and to do that, you just do</simpara>
<literallayout class="monospaced">git diff-index --cached HEAD</literallayout>
<simpara>Example: let&#8217;s say I had renamed <literal>commit.c</literal> to <literal>git-commit.c</literal>, and I had
done an <literal>update-index</literal> to make that effective in the index file.
<literal>git diff-files</literal> wouldn&#8217;t show anything at all, since the index file
matches my working directory. But doing a <emphasis>git-diff-index</emphasis> does:</simpara>
<literallayout class="monospaced">torvalds@ppc970:~/git&gt; git diff-index --cached HEAD
-100644 blob    4161aecc6700a2eb579e842af0b7f22b98443f74        commit.c
+100644 blob    4161aecc6700a2eb579e842af0b7f22b98443f74        git-commit.c</literallayout>
<simpara>You can see easily that the above is a rename.</simpara>
<simpara>In fact, <literal>git diff-index --cached</literal> <emphasis role="strong">should</emphasis> always be entirely equivalent to
actually doing a <emphasis>git-write-tree</emphasis> and comparing that. Except this one is much
nicer for the case where you just want to check where you are.</simpara>
<simpara>So doing a <emphasis>git-diff-index --cached</emphasis> is basically very useful when you are
asking yourself "what have I already marked for being committed, and
what&#8217;s the difference to a previous tree".</simpara>
</simplesect>
<simplesect id="_non_cached_mode">
<title>Non-cached Mode</title>
<simpara>The "non-cached" mode takes a different approach, and is potentially
the more useful of the two in that what it does can&#8217;t be emulated with
a <emphasis>git-write-tree</emphasis> + <emphasis>git-diff-tree</emphasis>. Thus that&#8217;s the default mode.
The non-cached version asks the question:</simpara>
<literallayout class="monospaced">show me the differences between HEAD and the currently checked out
tree - index contents _and_ files that aren't up-to-date</literallayout>
<simpara>which is obviously a very useful question too, since that tells you what
you <emphasis role="strong">could</emphasis> commit. Again, the output matches the <emphasis>git-diff-tree -r</emphasis>
output to a tee, but with a twist.</simpara>
<simpara>The twist is that if some file doesn&#8217;t match the index, we don&#8217;t have
a backing store thing for it, and we use the magic "all-zero" sha1 to
show that. So let&#8217;s say that you have edited <literal>kernel/sched.c</literal>, but
have not actually done a <emphasis>git-update-index</emphasis> on it yet - there is no
"object" associated with the new state, and you get:</simpara>
<literallayout class="monospaced">torvalds@ppc970:~/v2.6/linux&gt; git diff-index HEAD
*100644-&gt;100664 blob    7476bb......-&gt;000000......      kernel/sched.c</literallayout>
<simpara>i.e., it shows that the tree has changed, and that <literal>kernel/sched.c</literal> has is
not up-to-date and may contain new stuff. The all-zero sha1 means that to
get the real diff, you need to look at the object in the working directory
directly rather than do an object-to-object diff.</simpara>
<note><simpara>As with other commands of this type, <emphasis>git-diff-index</emphasis> does not
actually look at the contents of the file at all. So maybe
<literal>kernel/sched.c</literal> hasn&#8217;t actually changed, and it&#8217;s just that you
touched it. In either case, it&#8217;s a note that you need to
<emphasis>git-update-index</emphasis> it to make the index be in sync.</simpara></note>
<note><simpara>You can have a mixture of files show up as "has been updated"
and "is still dirty in the working directory" together. You can always
tell which file is in which state, since the "has been updated" ones
show a valid sha1, and the "not in sync with the index" ones will
always have the special all-zero sha1.</simpara></note>
</simplesect>
<simplesect id="_author">
<title>Author</title>
<simpara>Written by Linus Torvalds &lt;<ulink url="mailto:torvalds@osdl.org">torvalds@osdl.org</ulink>&gt;</simpara>
</simplesect>
<simplesect id="_documentation">
<title>Documentation</title>
<simpara>Documentation by David Greaves, Junio C Hamano and the git-list &lt;<ulink url="mailto:git@vger.kernel.org">git@vger.kernel.org</ulink>&gt;.</simpara>
</simplesect>
<simplesect id="_git">
<title>GIT</title>
<simpara>Part of the <xref linkend="git(1)"/> suite</simpara>
</simplesect>
</article>
