<?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-tree(1)">
<articleinfo>
    <title>git-diff-tree(1)</title>
        <indexterm>
                <primary>git-diff-tree(1)</primary>
        </indexterm>
</articleinfo>
<simplesect id="_name">
<title>NAME</title>
<simpara>git-diff-tree - Compares the content and mode of blobs found via two tree objects</simpara>
</simplesect>
<simplesect id="_synopsis">
<title>SYNOPSIS</title>
<blockquote>
<literallayout><emphasis>git diff-tree</emphasis> [--stdin] [-m] [-s] [-v] [--no-commit-id] [--pretty]
              [-t] [-r] [-c | --cc] [--root] [&lt;common diff options&gt;]
              &lt;tree-ish&gt; [&lt;tree-ish&gt;] [&lt;path&gt;&#8230;]</literallayout>
</blockquote>
</simplesect>
<simplesect id="_description">
<title>DESCRIPTION</title>
<simpara>Compares the content and mode of the blobs found via two tree objects.</simpara>
<simpara>If there is only one &lt;tree-ish&gt; given, the commit is compared with its parents
(see --stdin below).</simpara>
<simpara>Note that <emphasis>git-diff-tree</emphasis> can use the tree encapsulated in a commit object.</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.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
&lt;path&gt;&#8230;
</term>
<listitem>
<simpara>
        If provided, the results are limited to a subset of files
        matching one of these prefix strings.
        i.e., file matches <literal>/^&lt;pattern1&gt;|&lt;pattern2&gt;|&#8230;/</literal>
        Note that this parameter does not provide any wildcard or regexp
        features.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-r
</term>
<listitem>
<simpara>
        recurse into sub-trees
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-t
</term>
<listitem>
<simpara>
        show tree entry itself as well as subtrees.  Implies -r.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--root
</term>
<listitem>
<simpara>
        When <emphasis>--root</emphasis> is specified the initial commit will be shown as a big
        creation event. This is equivalent to a diff against the NULL tree.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--stdin
</term>
<listitem>
<simpara>
        When <emphasis>--stdin</emphasis> is specified, the command does not take
        &lt;tree-ish&gt; arguments from the command line.  Instead, it
        reads lines containing either two &lt;tree&gt;, one &lt;commit&gt;, or a
        list of &lt;commit&gt; from its standard input.  (Use a single space
        as separator.)
</simpara>
<simpara>When two trees are given, it compares the first tree with the second.
When a single commit is given, it compares the commit with its
parents.  The remaining commits, when given, are used as if they are
parents of the first commit.</simpara>
<simpara>When comparing two trees, the ID of both trees (separated by a space
and terminated by a newline) is printed before the difference.  When
comparing commits, the ID of the first (or only) commit, followed by a
newline, is printed.</simpara>
<simpara>The following flags further affect the behavior when comparing
commits (but not trees).</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-m
</term>
<listitem>
<simpara>
        By default, <emphasis>git-diff-tree --stdin</emphasis> does not show
        differences for merge commits.  With this flag, it shows
        differences to that commit from all of its parents. See
        also <emphasis>-c</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-s
</term>
<listitem>
<simpara>
        By default, <emphasis>git-diff-tree --stdin</emphasis> shows differences,
        either in machine-readable form (without <emphasis>-p</emphasis>) or in patch
        form (with <emphasis>-p</emphasis>).  This output can be suppressed.  It is
        only useful with <emphasis>-v</emphasis> flag.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-v
</term>
<listitem>
<simpara>
        This flag causes <emphasis>git-diff-tree --stdin</emphasis> to also show
        the commit message before the differences.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--pretty[=<emphasis>&lt;format&gt;</emphasis>]
</term>
<listitem>
<simpara>
        Pretty-print the contents of the commit logs in a given format,
        where <emphasis>&lt;format&gt;</emphasis> can be one of <emphasis>oneline</emphasis>, <emphasis>short</emphasis>, <emphasis>medium</emphasis>,
        <emphasis>full</emphasis>, <emphasis>fuller</emphasis>, <emphasis>email</emphasis>, <emphasis>raw</emphasis> and <emphasis>format:&lt;string&gt;</emphasis>.
        When omitted, the format defaults to <emphasis>medium</emphasis>.
</simpara>
<simpara>Note: you can specify the default pretty format in the repository
configuration (see <xref linkend="git-config(1)"/>).</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--abbrev-commit
</term>
<listitem>
<simpara>
        Instead of showing the full 40-byte hexadecimal commit object
        name, show only a partial prefix.  Non default number of
        digits can be specified with "--abbrev=&lt;n&gt;" (which also modifies
        diff output, if it is displayed).
</simpara>
<simpara>This should make "--pretty=oneline" a whole lot more readable for
people using 80-column terminals.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--encoding[=&lt;encoding&gt;]
</term>
<listitem>
<simpara>
        The commit objects record the encoding used for the log message
        in their encoding header; this option can be used to tell the
        command to re-code the commit log message in the encoding
        preferred by the user.  For non plumbing commands this
        defaults to UTF-8.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--no-commit-id
</term>
<listitem>
<simpara>
        <emphasis>git-diff-tree</emphasis> outputs a line with the commit ID when
        applicable.  This flag suppressed the commit ID output.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-c
</term>
<listitem>
<simpara>
        This flag changes the way a merge commit is displayed
        (which means it is useful only when the command is given
        one &lt;tree-ish&gt;, or <emphasis>--stdin</emphasis>).  It shows the differences
        from each of the parents to the merge result simultaneously
        instead of showing pairwise diff between a parent and the
        result one at a time (which is what the <emphasis>-m</emphasis> option does).
        Furthermore, it lists only files which were modified
        from all parents.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--cc
</term>
<listitem>
<simpara>
        This flag changes the way a merge commit patch is displayed,
        in a similar way to the <emphasis>-c</emphasis> option. It implies the <emphasis>-c</emphasis>
        and <emphasis>-p</emphasis> options and further compresses the patch output
        by omitting uninteresting hunks whose the contents in the parents
        have only two variants and the merge result picks one of them
        without modification.  When all hunks are uninteresting, the commit
        itself and the commit log message is not shown, just like in any other
        "empty diff" case.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--always
</term>
<listitem>
<simpara>
        Show the commit itself and the commit log message even
        if the diff itself is empty.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="_pretty_formats">
<title>PRETTY FORMATS</title>
<simpara>If the commit is a merge, and if the pretty-format
is not <emphasis>oneline</emphasis>, <emphasis>email</emphasis> or <emphasis>raw</emphasis>, an additional line is
inserted before the <emphasis>Author:</emphasis> line.  This line begins with
"Merge: " and the sha1s of ancestral commits are printed,
separated by spaces.  Note that the listed commits may not
necessarily be the list of the <emphasis role="strong">direct</emphasis> parent commits if you
have limited your view of history: for example, if you are
only interested in changes related to a certain directory or
file.</simpara>
<simpara>Here are some additional details for each format:</simpara>
<itemizedlist>
<listitem>
<simpara>
<emphasis>oneline</emphasis>
</simpara>
<literallayout class="monospaced">&lt;sha1&gt; &lt;title line&gt;</literallayout>
<simpara>This is designed to be as compact as possible.</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>short</emphasis>
</simpara>
<literallayout class="monospaced">commit &lt;sha1&gt;
Author: &lt;author&gt;</literallayout>
<literallayout class="monospaced">&lt;title line&gt;</literallayout>
</listitem>
<listitem>
<simpara>
<emphasis>medium</emphasis>
</simpara>
<literallayout class="monospaced">commit &lt;sha1&gt;
Author: &lt;author&gt;
Date:   &lt;author date&gt;</literallayout>
<literallayout class="monospaced">&lt;title line&gt;</literallayout>
<literallayout class="monospaced">&lt;full commit message&gt;</literallayout>
</listitem>
<listitem>
<simpara>
<emphasis>full</emphasis>
</simpara>
<literallayout class="monospaced">commit &lt;sha1&gt;
Author: &lt;author&gt;
Commit: &lt;committer&gt;</literallayout>
<literallayout class="monospaced">&lt;title line&gt;</literallayout>
<literallayout class="monospaced">&lt;full commit message&gt;</literallayout>
</listitem>
<listitem>
<simpara>
<emphasis>fuller</emphasis>
</simpara>
<literallayout class="monospaced">commit &lt;sha1&gt;
Author:     &lt;author&gt;
AuthorDate: &lt;author date&gt;
Commit:     &lt;committer&gt;
CommitDate: &lt;committer date&gt;</literallayout>
<literallayout class="monospaced">&lt;title line&gt;</literallayout>
<literallayout class="monospaced">&lt;full commit message&gt;</literallayout>
</listitem>
<listitem>
<simpara>
<emphasis>email</emphasis>
</simpara>
<literallayout class="monospaced">From &lt;sha1&gt; &lt;date&gt;
From: &lt;author&gt;
Date: &lt;author date&gt;
Subject: [PATCH] &lt;title line&gt;</literallayout>
<literallayout class="monospaced">&lt;full commit message&gt;</literallayout>
</listitem>
<listitem>
<simpara>
<emphasis>raw</emphasis>
</simpara>
<simpara>The <emphasis>raw</emphasis> format shows the entire commit exactly as
stored in the commit object.  Notably, the SHA1s are
displayed in full, regardless of whether --abbrev or
--no-abbrev are used, and <emphasis>parents</emphasis> information show the
true parent commits, without taking grafts nor history
simplification into account.</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>format:</emphasis>
</simpara>
<simpara>The <emphasis>format:</emphasis> format allows you to specify which information
you want to show. It works a little bit like printf format,
with the notable exception that you get a newline with <emphasis>%n</emphasis>
instead of <emphasis>\n</emphasis>.</simpara>
<simpara>E.g, <emphasis>format:"The author of %h was %an, %ar%nThe title was &gt;&gt;%s&lt;&lt;%n"</emphasis>
would show something like this:</simpara>
<literallayout>The author of fe6e0ee was Junio C Hamano, 23 hours ago
The title was &gt;&gt;t4119: test autocomputing -p&lt;n&gt; for traditional diff input.&lt;&lt;</literallayout>
<simpara>The placeholders are:</simpara>
<itemizedlist>
<listitem>
<simpara>
<emphasis>%H</emphasis>: commit hash
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%h</emphasis>: abbreviated commit hash
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%T</emphasis>: tree hash
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%t</emphasis>: abbreviated tree hash
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%P</emphasis>: parent hashes
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%p</emphasis>: abbreviated parent hashes
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%an</emphasis>: author name
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%aN</emphasis>: author name (respecting .mailmap)
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%ae</emphasis>: author email
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%aE</emphasis>: author email (respecting .mailmap)
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%ad</emphasis>: author date (format respects --date= option)
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%aD</emphasis>: author date, RFC2822 style
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%ar</emphasis>: author date, relative
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%at</emphasis>: author date, UNIX timestamp
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%ai</emphasis>: author date, ISO 8601 format
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%cn</emphasis>: committer name
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%cN</emphasis>: committer name (respecting .mailmap)
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%ce</emphasis>: committer email
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%cE</emphasis>: committer email (respecting .mailmap)
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%cd</emphasis>: committer date
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%cD</emphasis>: committer date, RFC2822 style
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%cr</emphasis>: committer date, relative
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%ct</emphasis>: committer date, UNIX timestamp
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%ci</emphasis>: committer date, ISO 8601 format
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%d</emphasis>: ref names, like the --decorate option of <xref linkend="git-log(1)"/>
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%e</emphasis>: encoding
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%s</emphasis>: subject
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%b</emphasis>: body
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%Cred</emphasis>: switch color to red
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%Cgreen</emphasis>: switch color to green
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%Cblue</emphasis>: switch color to blue
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%Creset</emphasis>: reset color
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%C(&#8230;)</emphasis>: color specification, as described in color.branch.* config option
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%m</emphasis>: left, right or boundary mark
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%n</emphasis>: newline
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>%x00</emphasis>: print a byte from a hex code
</simpara>
</listitem>
</itemizedlist>
</listitem>
<listitem>
<simpara>
<emphasis>tformat:</emphasis>
</simpara>
<simpara>The <emphasis>tformat:</emphasis> format works exactly like <emphasis>format:</emphasis>, except that it
provides "terminator" semantics instead of "separator" semantics. In
other words, each commit has the message terminator character (usually a
newline) appended, rather than a separator placed between entries.
This means that the final entry of a single-line format will be properly
terminated with a new line, just as the "oneline" format does.
For example:</simpara>
<literallayout>$ git log -2 --pretty=format:%h 4da45bef \
  | perl -pe '$_ .= " -- NO NEWLINE\n" unless /\n/'
4da45be
7134973 -- NO NEWLINE

$ git log -2 --pretty=tformat:%h 4da45bef \
  | perl -pe '$_ .= " -- NO NEWLINE\n" unless /\n/'
4da45be
7134973</literallayout>
</listitem>
</itemizedlist>
</simplesect>
<simplesect id="_limiting_output">
<title>Limiting Output</title>
<simpara>If you&#8217;re only interested in differences in a subset of files, for
example some architecture-specific files, you might do:</simpara>
<literallayout class="monospaced">git diff-tree -r &lt;tree-ish&gt; &lt;tree-ish&gt; arch/ia64 include/asm-ia64</literallayout>
<simpara>and it will only show you what changed in those two directories.</simpara>
<simpara>Or if you are searching for what changed in just <literal>kernel/sched.c</literal>, just do</simpara>
<literallayout class="monospaced">git diff-tree -r &lt;tree-ish&gt; &lt;tree-ish&gt; kernel/sched.c</literallayout>
<simpara>and it will ignore all differences to other files.</simpara>
<simpara>The pattern is always the prefix, and is matched exactly.  There are no
wildcards.  Even stricter, it has to match a complete path component.
I.e. "foo" does not pick up <literal>foobar.h</literal>.  "foo" does match <literal>foo/bar.h</literal>
so it can be used to name subdirectories.</simpara>
<simpara>An example of normal usage is:</simpara>
<literallayout class="monospaced">torvalds@ppc970:~/git&gt; git diff-tree 5319e4......
*100664-&gt;100664 blob    ac348b.......-&gt;a01513.......      git-fsck-objects.c</literallayout>
<simpara>which tells you that the last commit changed just one file (it&#8217;s from
this one:</simpara>
<literallayout>commit 3c6f7ca19ad4043e9e72fa94106f352897e651a8
tree 5319e4d609cdd282069cc4dce33c1db559539b03
parent b4e628ea30d5ab3606119d2ea5caeab141d38df7
author Linus Torvalds &lt;torvalds@ppc970.osdl.org&gt; Sat Apr 9 12:02:30 2005
committer Linus Torvalds &lt;torvalds@ppc970.osdl.org&gt; Sat Apr 9 12:02:30 2005

Make "git-fsck-objects" print out all the root commits it finds.

Once I do the reference tracking, I'll also make it print out all the
HEAD commits it finds, which is even more interesting.</literallayout>
<simpara>in case you care).</simpara>
</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="_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>
