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(
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(
1) Manual Page
409 <div class=
"sectionbody">
411 Show changes between commits, commit and working tree, etc
415 <h2 id=
"_synopsis">SYNOPSIS
</h2>
416 <div class=
"sectionbody">
417 <div class=
"verseblock">
418 <div class=
"verseblock-content"><em>git diff
</em> [options] [
<commit
>] [--] [
<path
>…]
419 <em>git diff
</em> [options] --cached [
<commit
>] [--] [
<path
>…]
420 <em>git diff
</em> [options]
<commit
> <commit
> [--] [
<path
>…]
421 <em>git diff
</em> [options] [--no-index] [--]
<path
> <path
></div>
422 <div class=
"verseblock-attribution">
425 <h2 id=
"_description">DESCRIPTION
</h2>
426 <div class=
"sectionbody">
427 <div class=
"paragraph"><p>Show changes between the working tree and the index or a tree, changes
428 between the index and a tree, changes between two trees, or changes
429 between two files on disk.
</p></div>
430 <div class=
"dlist"><dl>
432 <em>git diff
</em> [--options] [--] [
<path
>…]
436 This form is to view the changes you made relative to
437 the index (staging area for the next commit). In other
438 words, the differences are what you
<em>could
</em> tell git to
439 further add to the index but you still haven
’t. You can
440 stage these changes by using
<a href=
"git-add.html">git-add(
1)
</a>.
442 <div class=
"paragraph"><p>If exactly two paths are given and at least one points outside
443 the current repository,
<em>git diff
</em> will compare the two files /
444 directories. This behavior can be forced by --no-index.
</p></div>
447 <em>git diff
</em> [--options] --cached [
<commit
>] [--] [
<path
>…]
451 This form is to view the changes you staged for the next
452 commit relative to the named
<commit
>. Typically you
453 would want comparison with the latest commit, so if you
454 do not give
<commit
>, it defaults to HEAD.
455 If HEAD does not exist (e.g. unborned branches) and
456 <commit
> is not given, it shows all staged changes.
457 --staged is a synonym of --cached.
461 <em>git diff
</em> [--options]
<commit
> [--] [
<path
>…]
465 This form is to view the changes you have in your
466 working tree relative to the named
<commit
>. You can
467 use HEAD to compare it with the latest commit, or a
468 branch name to compare with the tip of a different
473 <em>git diff
</em> [--options]
<commit
> <commit
> [--] [
<path
>…]
477 This is to view the changes between two arbitrary
482 <em>git diff
</em> [--options]
<commit
>..
<commit
> [--] [
<path
>…]
486 This is synonymous to the previous form. If
<commit
> on
487 one side is omitted, it will have the same effect as
492 <em>git diff
</em> [--options]
<commit
>...
<commit
> [--] [
<path
>…]
496 This form is to view the changes on the branch containing
497 and up to the second
<commit
>, starting at a common ancestor
498 of both
<commit
>.
"git diff A...B" is equivalent to
499 "git diff $(git-merge-base A B) B". You can omit any one
500 of
<commit
>, which has the same effect as using HEAD instead.
504 <div class=
"paragraph"><p>Just in case if you are doing something exotic, it should be
505 noted that all of the
<commit
> in the above description, except
506 in the last two forms that use
".." notations, can be any
507 <tree
>. The third form (
<em>git diff
<commit
> <commit
></em>) can also
508 be used to compare two
<blob
> objects.
</p></div>
509 <div class=
"paragraph"><p>For a more complete list of ways to spell
<commit
>, see
510 "SPECIFYING REVISIONS" section in
<a href=
"gitrevisions.html">gitrevisions(
7)
</a>.
511 However,
"diff" is about comparing two
<em>endpoints
</em>, not ranges,
512 and the range notations (
"<commit>..<commit>" and
513 "<commit>...<commit>") do not mean a range as defined in the
514 "SPECIFYING RANGES" section in
<a href=
"gitrevisions.html">gitrevisions(
7)
</a>.
</p></div>
516 <h2 id=
"_options">OPTIONS
</h2>
517 <div class=
"sectionbody">
518 <div class=
"dlist"><dl>
530 Generate patch (see section on generating patches).
542 Generate diffs with
<n
> lines of context instead of
552 Generate the raw format.
561 Synonym for
<tt>-p --raw
</tt>.
569 Generate a diff using the
"patience diff" algorithm.
573 --stat[=
<width
>[,
<name-width
>]]
577 Generate a diffstat. You can override the default
578 output width for
80-column terminal by
<tt>--stat=
<width
></tt>.
579 The width of the filename part can be controlled by
580 giving another width to it separated by a comma.
588 Similar to
<tt>--stat
</tt>, but shows number of added and
589 deleted lines in decimal notation and pathname without
590 abbreviation, to make it more machine friendly. For
591 binary files, outputs two
<tt>-
</tt> instead of saying
600 Output only the last line of the
<tt>--stat
</tt> format containing total
601 number of modified files, as well as number of added and deleted
606 --dirstat[=
<limit
>]
610 Output the distribution of relative amount of changes (number of lines added or
611 removed) for each sub-directory. Directories with changes below
612 a cut-off percent (
3% by default) are not shown. The cut-off percent
613 can be set with
<tt>--dirstat=
<limit
></tt>. Changes in a child directory are not
614 counted for the parent directory, unless
<tt>--cumulative
</tt> is used.
616 <div class=
"paragraph"><p>Note that the
<tt>--dirstat
</tt> option computes the changes while ignoring
617 the amount of pure code movements within a file. In other words,
618 rearranging lines in a file is not counted as much as other changes.
</p></div>
621 --dirstat-by-file[=
<limit
>]
625 Same as
<tt>--dirstat
</tt>, but counts changed files instead of lines.
633 Output a condensed summary of extended header information
634 such as creations, renames and mode changes.
642 Synonym for
<tt>-p --stat
</tt>.
650 When
<tt>--raw
</tt>,
<tt>--numstat
</tt>,
<tt>--name-only
</tt> or
<tt>--name-status
</tt> has been
651 given, do not munge pathnames and use NULs as output field terminators.
653 <div class=
"paragraph"><p>Without this option, each pathname output will have TAB, LF, double quotes,
654 and backslash characters replaced with
<tt>\t
</tt>,
<tt>\n
</tt>,
<tt>\
"</tt>, and <tt>\\</tt>,
655 respectively, and the pathname will be enclosed in double quotes if
656 any of those replacements occurred.</p></div>
663 Show only names of changed files.
671 Show only names and status of changed files. See the description
672 of the <tt>--diff-filter</tt> option on what the status letters mean.
676 --submodule[=<format>]
680 Chose the output format for submodule differences. <format> can be one of
681 <em>short</em> and <em>log</em>. <em>short</em> just shows pairs of commit names, this format
682 is used when this option is not given. <em>log</em> is the default value for this
683 option and lists the commits in that commit range like the <em>summary</em>
684 option of <a href="git-submodule.html
">git-submodule(1)</a> does.
688 --color[=<when>]
693 The value must be always (the default), never, or auto.
701 Turn off colored diff, even when the configuration file
702 gives the default to color output.
703 Same as <tt>--color=never</tt>.
707 --word-diff[=<mode>]
711 Show a word diff, using the <mode> to delimit changed words.
712 By default, words are delimited by whitespace; see
713 <tt>--word-diff-regex</tt> below. The <mode> defaults to <em>plain</em>, and
716 <div class="dlist
"><dl>
722 Highlight changed words using only colors. Implies <tt>--color</tt>.
730 Show words as <tt>[-removed-]</tt> and <tt>{<tt>added</tt>}</tt>. Makes no
731 attempts to escape the delimiters if they appear in the input,
732 so the output may be ambiguous.
740 Use a special line-based format intended for script
741 consumption. Added/removed/unchanged runs are printed in the
742 usual unified diff format, starting with a <tt>+</tt>/<tt>-</tt>/` `
743 character at the beginning of the line and extending to the
744 end of the line. Newlines in the input are represented by a
745 tilde <tt>~</tt> on a line of its own.
753 Disable word diff again.
757 <div class="paragraph
"><p>Note that despite the name of the first mode, color is used to
758 highlight the changed parts in all modes if enabled.</p></div>
761 --word-diff-regex=<regex>
765 Use <regex> to decide what a word is, instead of considering
766 runs of non-whitespace to be a word. Also implies
767 <tt>--word-diff</tt> unless it was already enabled.
769 <div class="paragraph
"><p>Every non-overlapping match of the
770 <regex> is considered a word. Anything between these matches is
771 considered whitespace and ignored(!) for the purposes of finding
772 differences. You may want to append <tt>|[^[:space:]]</tt> to your regular
773 expression to make sure that it matches all non-whitespace characters.
774 A match that contains a newline is silently truncated(!) at the
776 <div class="paragraph
"><p>The regex can also be set via a diff driver or configuration option, see
777 <a href="gitattributes.html
">gitattributes(1)</a> or <a href="git-config.html
">git-config(1)</a>. Giving it explicitly
778 overrides any diff driver or configuration setting. Diff drivers
779 override configuration settings.</p></div>
782 --color-words[=<regex>]
786 Equivalent to <tt>--word-diff=color</tt> plus (if a regex was
787 specified) <tt>--word-diff-regex=<regex></tt>.
795 Turn off rename detection, even when the configuration
796 file gives the default to do so.
804 Warn if changes introduce trailing whitespace
805 or an indent that uses a space before a tab. Exits with
806 non-zero status if problems are found. Not compatible with
815 Instead of the first handful of characters, show the full
816 pre- and post-image blob object names on the "index
"
817 line when generating patch format output.
825 In addition to <tt>--full-index</tt>, output a binary diff that
826 can be applied with <tt>git-apply</tt>.
834 Instead of showing the full 40-byte hexadecimal object
835 name in diff-raw format output and diff-tree header
836 lines, show only a partial prefix. This is
837 independent of the <tt>--full-index</tt> option above, which controls
838 the diff-patch output format. Non default number of
839 digits can be specified with <tt>--abbrev=<n></tt>.
843 -B[<n>][/<m>]
846 --break-rewrites[=[<n>][/<m>]]
850 Break complete rewrite changes into pairs of delete and
851 create. This serves two purposes:
853 <div class="paragraph
"><p>It affects the way a change that amounts to a total rewrite of a file
854 not as a series of deletion and insertion mixed together with a very
855 few lines that happen to match textually as the context, but as a
856 single deletion of everything old followed by a single insertion of
857 everything new, and the number <tt>m</tt> controls this aspect of the -B
858 option (defaults to 60%). <tt>-B/70%</tt> specifies that less than 30% of the
859 original should remain in the result for git to consider it a total
860 rewrite (i.e. otherwise the resulting patch will be a series of
861 deletion and insertion mixed together with context lines).</p></div>
862 <div class="paragraph
"><p>When used with -M, a totally-rewritten file is also considered as the
863 source of a rename (usually -M only considers a file that disappeared
864 as the source of a rename), and the number <tt>n</tt> controls this aspect of
865 the -B option (defaults to 50%). <tt>-B20%</tt> specifies that a change with
866 addition and deletion compared to 20% or more of the file’s size are
867 eligible for being picked up as a possible source of a rename to
868 another file.</p></div>
874 --find-renames[=<n>]
879 If <tt>n</tt> is specified, it is a is a threshold on the similarity
880 index (i.e. amount of addition/deletions compared to the
881 file’s size). For example, <tt>-M90%</tt> means git should consider a
882 delete/add pair to be a rename if more than 90% of the file
883 hasn’t changed.
890 --find-copies[=<n>]
894 Detect copies as well as renames. See also <tt>--find-copies-harder</tt>.
895 If <tt>n</tt> is specified, it has the same meaning as for <tt>-M<n></tt>.
903 For performance reasons, by default, <tt>-C</tt> option finds copies only
904 if the original file of the copy was modified in the same
905 changeset. This flag makes the command
906 inspect unmodified files as candidates for the source of
907 copy. This is a very expensive operation for large
908 projects, so use it with caution. Giving more than one
909 <tt>-C</tt> option has the same effect.
916 --irreversible-delete
920 Omit the preimage for deletes, i.e. print only the header but not
921 the diff between the preimage and <tt>/dev/null</tt>. The resulting patch
922 is not meant to be applied with <tt>patch</tt> nor <tt>git apply</tt>; this is
923 solely for people who want to just concentrate on reviewing the
924 text after the change. In addition, the output obviously lack
925 enough information to apply such a patch in reverse, even manually,
926 hence the name of the option.
928 <div class="paragraph
"><p>When used together with <tt>-B</tt>, omit also the preimage in the deletion part
929 of a delete/create pair.</p></div>
936 The <tt>-M</tt> and <tt>-C</tt> options require O(n^2) processing time where n
937 is the number of potential rename/copy targets. This
938 option prevents rename/copy detection from running if
939 the number of rename/copy targets exceeds the specified
944 --diff-filter=[(A|C|D|M|R|T|U|X|B)…[*]]
948 Select only files that are Added (<tt>A</tt>), Copied (<tt>C</tt>),
949 Deleted (<tt>D</tt>), Modified (<tt>M</tt>), Renamed (<tt>R</tt>), have their
950 type (i.e. regular file, symlink, submodule, …) changed (<tt>T</tt>),
951 are Unmerged (<tt>U</tt>), are
952 Unknown (<tt>X</tt>), or have had their pairing Broken (<tt>B</tt>).
953 Any combination of the filter characters (including none) can be used.
954 When <tt>*</tt> (All-or-none) is added to the combination, all
955 paths are selected if there is any file that matches
956 other criteria in the comparison; if there is no file
957 that matches other criteria, nothing is selected.
965 Look for differences that introduce or remove an instance of
966 <string>. Note that this is different than the string simply
967 appearing in diff output; see the <em>pickaxe</em> entry in
968 <a href="gitdiffcore.html
">gitdiffcore(7)</a> for more details.
976 Look for differences whose added or removed line matches
977 the given <regex>.
985 When <tt>-S</tt> or <tt>-G</tt> finds a change, show all the changes in that
986 changeset, not just the files that contain the change
995 Make the <string> not a plain string but an extended POSIX
1004 Output the patch in the order specified in the
1005 <orderfile>, which has one shell glob pattern per line.
1008 <dt class="hdlist1
">
1013 Swap two inputs; that is, show differences from index or
1014 on-disk file to tree contents.
1017 <dt class="hdlist1
">
1018 --relative[=<path>]
1022 When run from a subdirectory of the project, it can be
1023 told to exclude changes outside the directory and show
1024 pathnames relative to it with this option. When you are
1025 not in a subdirectory (e.g. in a bare repository), you
1026 can name which subdirectory to make the output relative
1027 to by giving a <path> as an argument.
1030 <dt class="hdlist1
">
1033 <dt class="hdlist1
">
1038 Treat all files as text.
1041 <dt class="hdlist1
">
1042 --ignore-space-at-eol
1046 Ignore changes in whitespace at EOL.
1049 <dt class="hdlist1
">
1052 <dt class="hdlist1
">
1053 --ignore-space-change
1057 Ignore changes in amount of whitespace. This ignores whitespace
1058 at line end, and considers all other sequences of one or
1059 more whitespace characters to be equivalent.
1062 <dt class="hdlist1
">
1065 <dt class="hdlist1
">
1070 Ignore whitespace when comparing lines. This ignores
1071 differences even if one line has whitespace where the other
1075 <dt class="hdlist1
">
1076 --inter-hunk-context=<lines>
1080 Show the context between diff hunks, up to the specified number
1081 of lines, thereby fusing hunks that are close to each other.
1084 <dt class="hdlist1
">
1089 Make the program exit with codes similar to diff(1).
1090 That is, it exits with 1 if there were differences and
1091 0 means no differences.
1094 <dt class="hdlist1
">
1099 Disable all output of the program. Implies <tt>--exit-code</tt>.
1102 <dt class="hdlist1
">
1107 Allow an external diff helper to be executed. If you set an
1108 external diff driver with <a href="gitattributes.html
">gitattributes(5)</a>, you need
1109 to use this option with <a href="git-log.html
">git-log(1)</a> and friends.
1112 <dt class="hdlist1
">
1117 Disallow external diff drivers.
1120 <dt class="hdlist1
">
1121 --ignore-submodules[=<when>]
1125 Ignore changes to submodules in the diff generation. <when> can be
1126 either "none
", "untracked
", "dirty
" or "all
", which is the default
1127 Using "none
" will consider the submodule modified when it either contains
1128 untracked or modified files or its HEAD differs from the commit recorded
1129 in the superproject and can be used to override any settings of the
1130 <em>ignore</em> option in <a href="git-config.html
">git-config(1)</a> or <a href="gitmodules.html
">gitmodules(5)</a>. When
1131 "untracked
" is used submodules are not considered dirty when they only
1132 contain untracked content (but they are still scanned for modified
1133 content). Using "dirty
" ignores all changes to the work tree of submodules,
1134 only changes to the commits stored in the superproject are shown (this was
1135 the behavior until 1.7.0). Using "all
" hides all changes to submodules.
1138 <dt class="hdlist1
">
1139 --src-prefix=<prefix>
1143 Show the given source prefix instead of "a/
".
1146 <dt class="hdlist1
">
1147 --dst-prefix=<prefix>
1151 Show the given destination prefix instead of "b/
".
1154 <dt class="hdlist1
">
1159 Do not show any source or destination prefix.
1163 <div class="paragraph
"><p>For more detailed explanation on these common options, see also
1164 <a href="gitdiffcore.html
">gitdiffcore(7)</a>.</p></div>
1165 <div class="dlist
"><dl>
1166 <dt class="hdlist1
">
1171 The <paths> parameters, when given, are used to limit
1172 the diff to the named paths (you can give directory
1173 names and get diff for all files under them).
1178 <h2 id="_raw_output_format
">Raw output format</h2>
1179 <div class="sectionbody
">
1180 <div class="paragraph
"><p>The raw output format from "git-diff-index
", "git-diff-tree
",
1181 "git-diff-files
" and "git diff --raw
" are very similar.</p></div>
1182 <div class="paragraph
"><p>These commands all compare two sets of things; what is
1183 compared differs:</p></div>
1184 <div class="dlist
"><dl>
1185 <dt class="hdlist1
">
1186 git-diff-index <tree-ish>
1190 compares the <tree-ish> and the files on the filesystem.
1193 <dt class="hdlist1
">
1194 git-diff-index --cached <tree-ish>
1198 compares the <tree-ish> and the index.
1201 <dt class="hdlist1
">
1202 git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>…]
1206 compares the trees named by the two arguments.
1209 <dt class="hdlist1
">
1210 git-diff-files [<pattern>…]
1214 compares the index and the files on the filesystem.
1218 <div class="paragraph
"><p>The "git-diff-tree
" command begins its output by printing the hash of
1219 what is being compared. After that, all the commands print one output
1220 line per changed file.</p></div>
1221 <div class="paragraph
"><p>An output line is formatted this way:</p></div>
1222 <div class="listingblock
">
1223 <div class="content
">
1224 <pre><tt>in-place edit :100644 100644 bcd1234... 0123456... M file0
1225 copy-edit :100644 100644 abcd123... 1234567... C68 file1 file2
1226 rename-edit :100644 100644 abcd123... 1234567... R86 file1 file3
1227 create :000000 100644 0000000... 1234567... A file4
1228 delete :100644 000000 1234567... 0000000... D file5
1229 unmerged :000000 000000 0000000... 0000000... U file6</tt></pre>
1231 <div class="paragraph
"><p>That is, from the left to the right:</p></div>
1232 <div class="olist arabic
"><ol class="arabic
">
1240 mode for "src
"; 000000 if creation or unmerged.
1250 mode for "dst
"; 000000 if deletion or unmerged.
1260 sha1 for "src
"; 0{40} if creation or unmerged.
1270 sha1 for "dst
"; 0{40} if creation, unmerged or "look at work tree
".
1280 status, followed by optional "score
" number.
1285 a tab or a NUL when <em>-z</em> option is used.
1295 a tab or a NUL when <em>-z</em> option is used; only exists for C or R.
1300 path for "dst
"; only exists for C or R.
1305 an LF or a NUL when <em>-z</em> option is used, to terminate the record.
1309 <div class="paragraph
"><p>Possible status letters are:</p></div>
1310 <div class="ulist
"><ul>
1313 A: addition of a file
1318 C: copy of a file into a new one
1323 D: deletion of a file
1328 M: modification of the contents or mode of a file
1333 R: renaming of a file
1338 T: change in the type of the file
1343 U: file is unmerged (you must complete the merge before it can
1349 X: "unknown
" change type (most probably a bug, please report it)
1353 <div class="paragraph
"><p>Status letters C and R are always followed by a score (denoting the
1354 percentage of similarity between the source and target of the move or
1355 copy), and are the only ones to be so.</p></div>
1356 <div class="paragraph
"><p><sha1> is shown as all 0’s if a file is new on the filesystem
1357 and it is out of sync with the index.</p></div>
1358 <div class="paragraph
"><p>Example:</p></div>
1359 <div class="listingblock
">
1360 <div class="content
">
1361 <pre><tt>:100644 100644 5be4a4...... 000000...... M file.c</tt></pre>
1363 <div class="paragraph
"><p>When <tt>-z</tt> option is not used, TAB, LF, and backslash characters
1364 in pathnames are represented as <tt>\t</tt>, <tt>\n</tt>, and <tt>\\</tt>,
1365 respectively.</p></div>
1367 <h2 id="_diff_format_for_merges
">diff format for merges</h2>
1368 <div class="sectionbody
">
1369 <div class="paragraph
"><p>"git-diff-tree
", "git-diff-files
" and "git-diff --raw
"
1370 can take <em>-c</em> or <em>--cc</em> option
1371 to generate diff output also for merge commits. The output differs
1372 from the format described above in the following way:</p></div>
1373 <div class="olist arabic
"><ol class="arabic
">
1376 there is a colon for each parent
1381 there are more "src
" modes and "src
" sha1
1386 status is concatenated status characters for each parent
1391 no optional "score
" number
1396 single path, only for "dst
"
1400 <div class="paragraph
"><p>Example:</p></div>
1401 <div class="listingblock
">
1402 <div class="content
">
1403 <pre><tt>::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM describe.c</tt></pre>
1405 <div class="paragraph
"><p>Note that <em>combined diff</em> lists only files which were modified from
1406 all parents.</p></div>
1408 <h2 id="_generating_patches_with_p
">Generating patches with -p</h2>
1409 <div class="sectionbody
">
1410 <div class="paragraph
"><p>When "git-diff-index
", "git-diff-tree
", or "git-diff-files
" are run
1411 with a <em>-p</em> option, "git diff
" without the <em>--raw</em> option, or
1412 "git log
" with the "-p
" option, they
1413 do not produce the output described above; instead they produce a
1414 patch file. You can customize the creation of such patches via the
1415 GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables.</p></div>
1416 <div class="paragraph
"><p>What the -p option produces is slightly different from the traditional
1417 diff format:</p></div>
1418 <div class="olist arabic
"><ol class="arabic
">
1421 It is preceded with a "git diff
" header that looks like this:
1423 <div class="literalblock
">
1424 <div class="content
">
1425 <pre><tt>diff --git a/file1 b/file2</tt></pre>
1427 <div class="paragraph
"><p>The <tt>a/</tt> and <tt>b/</tt> filenames are the same unless rename/copy is
1428 involved. Especially, even for a creation or a deletion,
1429 <tt>/dev/null</tt> is <em>not</em> used in place of the <tt>a/</tt> or <tt>b/</tt> filenames.</p></div>
1430 <div class="paragraph
"><p>When rename/copy is involved, <tt>file1</tt> and <tt>file2</tt> show the
1431 name of the source file of the rename/copy and the name of
1432 the file that rename/copy produces, respectively.</p></div>
1436 It is followed by one or more extended header lines:
1438 <div class="literalblock
">
1439 <div class="content
">
1440 <pre><tt>old mode <mode>
1441 new mode <mode>
1442 deleted file mode <mode>
1443 new file mode <mode>
1444 copy from <path>
1445 copy to <path>
1446 rename from <path>
1447 rename to <path>
1448 similarity index <number>
1449 dissimilarity index <number>
1450 index <hash>..<hash> <mode></tt></pre>
1452 <div class="paragraph
"><p>File modes are printed as 6-digit octal numbers including the file type
1453 and file permission bits.</p></div>
1454 <div class="paragraph
"><p>Path names in extended headers do not include the <tt>a/</tt> and <tt>b/</tt> prefixes.</p></div>
1455 <div class="paragraph
"><p>The similarity index is the percentage of unchanged lines, and
1456 the dissimilarity index is the percentage of changed lines. It
1457 is a rounded down integer, followed by a percent sign. The
1458 similarity index value of 100% is thus reserved for two equal
1459 files, while 100% dissimilarity means that no line from the old
1460 file made it into the new one.</p></div>
1461 <div class="paragraph
"><p>The index line includes the SHA-1 checksum before and after the change.
1462 The <mode> is included if the file mode does not change; otherwise,
1463 separate lines indicate the old and the new mode.</p></div>
1467 TAB, LF, double quote and backslash characters in pathnames
1468 are represented as <tt>\t</tt>, <tt>\n</tt>, <tt>\"</tt> and
<tt>\\
</tt>, respectively.
1469 If there is need for such substitution then the whole
1470 pathname is put in double quotes.
1475 All the
<tt>file1
</tt> files in the output refer to files before the
1476 commit, and all the
<tt>file2
</tt> files refer to files after the commit.
1477 It is incorrect to apply each change to each file sequentially. For
1478 example, this patch will swap a and b:
1480 <div class=
"literalblock">
1481 <div class=
"content">
1482 <pre><tt>diff --git a/a b/b
1487 rename to a
</tt></pre>
1492 <h2 id=
"_combined_diff_format">combined diff format
</h2>
1493 <div class=
"sectionbody">
1494 <div class=
"paragraph"><p>Any diff-generating command can take the
‘-c` or
<tt>--cc
</tt> option to
1495 produce a
<em>combined diff
</em> when showing a merge. This is the default
1496 format when showing merges with
<a href=
"git-diff.html">git-diff(
1)
</a> or
1497 <a href=
"git-show.html">git-show(
1)
</a>. Note also that you can give the `-m
’ option to any
1498 of these commands to force generation of diffs with individual parents
1499 of a merge.
</p></div>
1500 <div class=
"paragraph"><p>A
<em>combined diff
</em> format looks like this:
</p></div>
1501 <div class=
"listingblock">
1502 <div class=
"content">
1503 <pre><tt>diff --combined describe.c
1504 index fabadb8,cc95eb0.
.4866510
1507 @@@ -
98,
20 -
98,
12 +
98,
20 @@@
1508 return (a_date
> b_date) ? -
1 : (a_date == b_date) ?
0 :
1;
1511 - static void describe(char *arg)
1512 -static void describe(struct commit *cmit, int last_one)
1513 ++static void describe(char *arg, int last_one)
1515 + unsigned char sha1[
20];
1516 + struct commit *cmit;
1517 struct commit_list *list;
1518 static int initialized =
0;
1519 struct commit_name *n;
1521 + if (get_sha1(arg, sha1)
< 0)
1522 + usage(describe_usage);
1523 + cmit = lookup_commit_reference(sha1);
1525 + usage(describe_usage);
1529 for_each_ref(get_name);
</tt></pre>
1531 <div class=
"olist arabic"><ol class=
"arabic">
1534 It is preceded with a
"git diff" header, that looks like
1535 this (when
<em>-c
</em> option is used):
1537 <div class=
"literalblock">
1538 <div class=
"content">
1539 <pre><tt>diff --combined file
</tt></pre>
1541 <div class=
"paragraph"><p>or like this (when
<em>--cc
</em> option is used):
</p></div>
1542 <div class=
"literalblock">
1543 <div class=
"content">
1544 <pre><tt>diff --cc file
</tt></pre>
1549 It is followed by one or more extended header lines
1550 (this example shows a merge with two parents):
1552 <div class=
"literalblock">
1553 <div class=
"content">
1554 <pre><tt>index
<hash
>,
<hash
>..
<hash
>
1555 mode
<mode
>,
<mode
>..
<mode
>
1556 new file mode
<mode
>
1557 deleted file mode
<mode
>,
<mode
></tt></pre>
1559 <div class=
"paragraph"><p>The
<tt>mode
<mode
>,
<mode
>..
<mode
></tt> line appears only if at least one of
1560 the
<mode
> is different from the rest. Extended headers with
1561 information about detected contents movement (renames and
1562 copying detection) are designed to work with diff of two
1563 <tree-ish
> and are not used by combined diff format.
</p></div>
1567 It is followed by two-line from-file/to-file header
1569 <div class=
"literalblock">
1570 <div class=
"content">
1572 +++ b/file
</tt></pre>
1574 <div class=
"paragraph"><p>Similar to two-line header for traditional
<em>unified
</em> diff
1575 format,
<tt>/dev/null
</tt> is used to signal created or deleted
1580 Chunk header format is modified to prevent people from
1581 accidentally feeding it to
<tt>patch -p1
</tt>. Combined diff format
1582 was created for review of merge commit changes, and was not
1583 meant for apply. The change is similar to the change in the
1584 extended
<em>index
</em> header:
1586 <div class=
"literalblock">
1587 <div class=
"content">
1588 <pre><tt>@@@
<from-file-range
> <from-file-range
> <to-file-range
> @@@
</tt></pre>
1590 <div class=
"paragraph"><p>There are (number of parents +
1)
<tt>@
</tt> characters in the chunk
1591 header for combined diff format.
</p></div>
1594 <div class=
"paragraph"><p>Unlike the traditional
<em>unified
</em> diff format, which shows two
1595 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
1596 added to B), or
<tt>" "</tt> (space
 — unchanged) prefix, this format
1597 compares two or more files file1, file2,
… with one file X, and
1598 shows how X differs from each of fileN. One column for each of
1599 fileN is prepended to the output line to note how X
’s line is
1600 different from it.
</p></div>
1601 <div class=
"paragraph"><p>A
<tt>-
</tt> character in the column N means that the line appears in
1602 fileN but it does not appear in the result. A
<tt>+
</tt> character
1603 in the column N means that the line appears in the result,
1604 and fileN does not have that line (in other words, the line was
1605 added, from the point of view of that parent).
</p></div>
1606 <div class=
"paragraph"><p>In the above example output, the function signature was changed
1607 from both files (hence two
<tt>-
</tt> removals from both file1 and
1608 file2, plus
<tt>++
</tt> to mean one line that was added does not appear
1609 in either file1 nor file2). Also eight other lines are the same
1610 from file1 but do not appear in file2 (hence prefixed with
<tt>+</tt>).
</p></div>
1611 <div class=
"paragraph"><p>When shown by
<tt>git diff-tree -c
</tt>, it compares the parents of a
1612 merge commit with the merge result (i.e. file1..fileN are the
1613 parents). When shown by
<tt>git diff-files -c
</tt>, it compares the
1614 two unresolved merge parents with the working tree file
1615 (i.e. file1 is stage
2 aka
"our version", file2 is stage
3 aka
1616 "their version").
</p></div>
1618 <h2 id=
"_other_diff_formats">other diff formats
</h2>
1619 <div class=
"sectionbody">
1620 <div class=
"paragraph"><p>The
<tt>--summary
</tt> option describes newly added, deleted, renamed and
1621 copied files. The
<tt>--stat
</tt> option adds diffstat(
1) graph to the
1622 output. These options can be combined with other options, such as
1623 <tt>-p
</tt>, and are meant for human consumption.
</p></div>
1624 <div class=
"paragraph"><p>When showing a change that involves a rename or a copy,
<tt>--stat
</tt> output
1625 formats the pathnames compactly by combining common prefix and suffix of
1626 the pathnames. For example, a change that moves
<tt>arch/i386/Makefile
</tt> to
1627 <tt>arch/x86/Makefile
</tt> while modifying
4 lines will be shown like this:
</p></div>
1628 <div class=
"listingblock">
1629 <div class=
"content">
1630 <pre><tt>arch/{i386 =
> x86}/Makefile |
4 +--
</tt></pre>
1632 <div class=
"paragraph"><p>The
<tt>--numstat
</tt> option gives the diffstat(
1) information but is designed
1633 for easier machine consumption. An entry in
<tt>--numstat
</tt> output looks
1634 like this:
</p></div>
1635 <div class=
"listingblock">
1636 <div class=
"content">
1638 3 1 arch/{i386 =
> x86}/Makefile
</tt></pre>
1640 <div class=
"paragraph"><p>That is, from left to right:
</p></div>
1641 <div class=
"olist arabic"><ol class=
"arabic">
1644 the number of added lines;
1654 the number of deleted lines;
1664 pathname (possibly with rename/copy information);
1673 <div class=
"paragraph"><p>When
<tt>-z
</tt> output option is in effect, the output is formatted this way:
</p></div>
1674 <div class=
"listingblock">
1675 <div class=
"content">
1676 <pre><tt>1 2 README NUL
1677 3 1 NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
</tt></pre>
1679 <div class=
"paragraph"><p>That is:
</p></div>
1680 <div class=
"olist arabic"><ol class=
"arabic">
1683 the number of added lines;
1693 the number of deleted lines;
1703 a NUL (only exists if renamed/copied);
1708 pathname in preimage;
1713 a NUL (only exists if renamed/copied);
1718 pathname in postimage (only exists if renamed/copied);
1727 <div class=
"paragraph"><p>The extra
<tt>NUL
</tt> before the preimage path in renamed case is to allow
1728 scripts that read the output to tell if the current record being read is
1729 a single-path record or a rename/copy record without reading ahead.
1730 After reading added and deleted lines, reading up to
<tt>NUL
</tt> would yield
1731 the pathname, but if that is
<tt>NUL
</tt>, the record will show two paths.
</p></div>
1733 <h2 id=
"_examples">EXAMPLES
</h2>
1734 <div class=
"sectionbody">
1735 <div class=
"dlist"><dl>
1736 <dt class=
"hdlist1">
1737 Various ways to check your working tree
1740 <div class=
"listingblock">
1741 <div class=
"content">
1742 <pre><tt>$ git diff
<b><1></b>
1743 $ git diff --cached
<b><2></b>
1744 $ git diff HEAD
<b><3></b></tt></pre>
1746 <div class=
"colist arabic"><ol>
1749 Changes in the working tree not yet staged for the next commit.
1754 Changes between the index and your last commit; what you
1755 would be committing if you run
"git commit" without
"-a" option.
1760 Changes in the working tree since your last commit; what you
1761 would be committing if you run
"git commit -a"
1766 <dt class=
"hdlist1">
1767 Comparing with arbitrary commits
1770 <div class=
"listingblock">
1771 <div class=
"content">
1772 <pre><tt>$ git diff test
<b><1></b>
1773 $ git diff HEAD -- ./test
<b><2></b>
1774 $ git diff HEAD^ HEAD
<b><3></b></tt></pre>
1776 <div class=
"colist arabic"><ol>
1779 Instead of using the tip of the current branch, compare with the
1780 tip of
"test" branch.
1785 Instead of comparing with the tip of
"test" branch, compare with
1786 the tip of the current branch, but limit the comparison to the
1792 Compare the version before the last commit and the last commit.
1797 <dt class=
"hdlist1">
1801 <div class=
"listingblock">
1802 <div class=
"content">
1803 <pre><tt>$ git diff topic master
<b><1></b>
1804 $ git diff topic..master
<b><2></b>
1805 $ git diff topic...master
<b><3></b></tt></pre>
1807 <div class=
"colist arabic"><ol>
1810 Changes between the tips of the topic and the master branches.
1820 Changes that occurred on the master branch since when the topic
1821 branch was started off it.
1826 <dt class=
"hdlist1">
1827 Limiting the diff output
1830 <div class=
"listingblock">
1831 <div class=
"content">
1832 <pre><tt>$ git diff --diff-filter=MRC
<b><1></b>
1833 $ git diff --name-status
<b><2></b>
1834 $ git diff arch/i386 include/asm-i386
<b><3></b></tt></pre>
1836 <div class=
"colist arabic"><ol>
1839 Show only modification, rename and copy, but not addition
1845 Show only names and the nature of change, but not actual
1851 Limit diff output to named subtrees.
1856 <dt class=
"hdlist1">
1857 Munging the diff output
1860 <div class=
"listingblock">
1861 <div class=
"content">
1862 <pre><tt>$ git diff --find-copies-harder -B -C
<b><1></b>
1863 $ git diff -R
<b><2></b></tt></pre>
1865 <div class=
"colist arabic"><ol>
1868 Spend extra cycles to find renames, copies and complete
1869 rewrites (very expensive).
1874 Output diff in reverse.
1881 <h2 id=
"_see_also">SEE ALSO
</h2>
1882 <div class=
"sectionbody">
1883 <div class=
"paragraph"><p>diff(
1),
1884 <a href=
"git-difftool.html">git-difftool(
1)
</a>,
1885 <a href=
"git-log.html">git-log(
1)
</a>,
1886 <a href=
"gitdiffcore.html">gitdiffcore(
7)
</a>,
1887 <a href=
"git-format-patch.html">git-format-patch(
1)
</a>,
1888 <a href=
"git-apply.html">git-apply(
1)
</a></p></div>
1890 <h2 id=
"_git">GIT
</h2>
1891 <div class=
"sectionbody">
1892 <div class=
"paragraph"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
1895 <div id=
"footer-text">
1896 Last updated
2011-
03-
15 23:
30:
13 UTC