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 --staged is a synonym of --cached.
459 <em>git diff
</em> [--options]
<commit
> [--] [
<path
>…]
463 This form is to view the changes you have in your
464 working tree relative to the named
<commit
>. You can
465 use HEAD to compare it with the latest commit, or a
466 branch name to compare with the tip of a different
471 <em>git diff
</em> [--options]
<commit
> <commit
> [--] [
<path
>…]
475 This is to view the changes between two arbitrary
480 <em>git diff
</em> [--options]
<commit
>..
<commit
> [--] [
<path
>…]
484 This is synonymous to the previous form. If
<commit
> on
485 one side is omitted, it will have the same effect as
490 <em>git diff
</em> [--options]
<commit
>...
<commit
> [--] [
<path
>…]
494 This form is to view the changes on the branch containing
495 and up to the second
<commit
>, starting at a common ancestor
496 of both
<commit
>.
"git diff A...B" is equivalent to
497 "git diff $(git-merge-base A B) B". You can omit any one
498 of
<commit
>, which has the same effect as using HEAD instead.
502 <div class=
"paragraph"><p>Just in case if you are doing something exotic, it should be
503 noted that all of the
<commit
> in the above description, except
504 in the last two forms that use
".." notations, can be any
505 <tree
>. The third form (
<em>git diff
<commit
> <commit
></em>) can also
506 be used to compare two
<blob
> objects.
</p></div>
507 <div class=
"paragraph"><p>For a more complete list of ways to spell
<commit
>, see
508 "SPECIFYING REVISIONS" section in
<a href=
"gitrevisions.html">gitrevisions(
7)
</a>.
509 However,
"diff" is about comparing two
<em>endpoints
</em>, not ranges,
510 and the range notations (
"<commit>..<commit>" and
511 "<commit>...<commit>") do not mean a range as defined in the
512 "SPECIFYING RANGES" section in
<a href=
"gitrevisions.html">gitrevisions(
7)
</a>.
</p></div>
514 <h2 id=
"_options">OPTIONS
</h2>
515 <div class=
"sectionbody">
516 <div class=
"dlist"><dl>
528 Generate patch (see section on generating patches).
540 Generate diffs with
<n
> lines of context instead of
550 Generate the raw format.
559 Synonym for
<tt>-p --raw
</tt>.
567 Generate a diff using the
"patience diff" algorithm.
571 --stat[=
<width
>[,
<name-width
>]]
575 Generate a diffstat. You can override the default
576 output width for
80-column terminal by
<tt>--stat=
<width
></tt>.
577 The width of the filename part can be controlled by
578 giving another width to it separated by a comma.
586 Similar to
<tt>--stat
</tt>, but shows number of added and
587 deleted lines in decimal notation and pathname without
588 abbreviation, to make it more machine friendly. For
589 binary files, outputs two
<tt>-
</tt> instead of saying
598 Output only the last line of the
<tt>--stat
</tt> format containing total
599 number of modified files, as well as number of added and deleted
604 --dirstat[=
<limit
>]
608 Output the distribution of relative amount of changes (number of lines added or
609 removed) for each sub-directory. Directories with changes below
610 a cut-off percent (
3% by default) are not shown. The cut-off percent
611 can be set with
<tt>--dirstat=
<limit
></tt>. Changes in a child directory are not
612 counted for the parent directory, unless
<tt>--cumulative
</tt> is used.
616 --dirstat-by-file[=
<limit
>]
620 Same as
<tt>--dirstat
</tt>, but counts changed files instead of lines.
628 Output a condensed summary of extended header information
629 such as creations, renames and mode changes.
637 Synonym for
<tt>-p --stat
</tt>.
645 When
<tt>--raw
</tt>,
<tt>--numstat
</tt>,
<tt>--name-only
</tt> or
<tt>--name-status
</tt> has been
646 given, do not munge pathnames and use NULs as output field terminators.
648 <div class=
"paragraph"><p>Without this option, each pathname output will have TAB, LF, double quotes,
649 and backslash characters replaced with
<tt>\t
</tt>,
<tt>\n
</tt>,
<tt>\
"</tt>, and <tt>\\</tt>,
650 respectively, and the pathname will be enclosed in double quotes if
651 any of those replacements occurred.</p></div>
658 Show only names of changed files.
666 Show only names and status of changed files. See the description
667 of the <tt>--diff-filter</tt> option on what the status letters mean.
671 --submodule[=<format>]
675 Chose the output format for submodule differences. <format> can be one of
676 <em>short</em> and <em>log</em>. <em>short</em> just shows pairs of commit names, this format
677 is used when this option is not given. <em>log</em> is the default value for this
678 option and lists the commits in that commit range like the <em>summary</em>
679 option of <a href="git-submodule.html
">git-submodule(1)</a> does.
683 --color[=<when>]
688 The value must be always (the default), never, or auto.
696 Turn off colored diff, even when the configuration file
697 gives the default to color output.
698 Same as <tt>--color=never</tt>.
702 --word-diff[=<mode>]
706 Show a word diff, using the <mode> to delimit changed words.
707 By default, words are delimited by whitespace; see
708 <tt>--word-diff-regex</tt> below. The <mode> defaults to <em>plain</em>, and
711 <div class="dlist
"><dl>
717 Highlight changed words using only colors. Implies <tt>--color</tt>.
725 Show words as <tt>[-removed-]</tt> and <tt>{<tt>added</tt>}</tt>. Makes no
726 attempts to escape the delimiters if they appear in the input,
727 so the output may be ambiguous.
735 Use a special line-based format intended for script
736 consumption. Added/removed/unchanged runs are printed in the
737 usual unified diff format, starting with a <tt>+</tt>/<tt>-</tt>/` `
738 character at the beginning of the line and extending to the
739 end of the line. Newlines in the input are represented by a
740 tilde <tt>~</tt> on a line of its own.
748 Disable word diff again.
752 <div class="paragraph
"><p>Note that despite the name of the first mode, color is used to
753 highlight the changed parts in all modes if enabled.</p></div>
756 --word-diff-regex=<regex>
760 Use <regex> to decide what a word is, instead of considering
761 runs of non-whitespace to be a word. Also implies
762 <tt>--word-diff</tt> unless it was already enabled.
764 <div class="paragraph
"><p>Every non-overlapping match of the
765 <regex> is considered a word. Anything between these matches is
766 considered whitespace and ignored(!) for the purposes of finding
767 differences. You may want to append <tt>|[^[:space:]]</tt> to your regular
768 expression to make sure that it matches all non-whitespace characters.
769 A match that contains a newline is silently truncated(!) at the
771 <div class="paragraph
"><p>The regex can also be set via a diff driver or configuration option, see
772 <a href="gitattributes.html
">gitattributes(1)</a> or <a href="git-config.html
">git-config(1)</a>. Giving it explicitly
773 overrides any diff driver or configuration setting. Diff drivers
774 override configuration settings.</p></div>
777 --color-words[=<regex>]
781 Equivalent to <tt>--word-diff=color</tt> plus (if a regex was
782 specified) <tt>--word-diff-regex=<regex></tt>.
790 Turn off rename detection, even when the configuration
791 file gives the default to do so.
799 Warn if changes introduce trailing whitespace
800 or an indent that uses a space before a tab. Exits with
801 non-zero status if problems are found. Not compatible with
810 Instead of the first handful of characters, show the full
811 pre- and post-image blob object names on the "index
"
812 line when generating patch format output.
820 In addition to <tt>--full-index</tt>, output a binary diff that
821 can be applied with <tt>git-apply</tt>.
829 Instead of showing the full 40-byte hexadecimal object
830 name in diff-raw format output and diff-tree header
831 lines, show only a partial prefix. This is
832 independent of the <tt>--full-index</tt> option above, which controls
833 the diff-patch output format. Non default number of
834 digits can be specified with <tt>--abbrev=<n></tt>.
838 -B[<n>][/<m>]
841 --break-rewrites[=[<n>][/<m>]]
845 Break complete rewrite changes into pairs of delete and
846 create. This serves two purposes:
848 <div class="paragraph
"><p>It affects the way a change that amounts to a total rewrite of a file
849 not as a series of deletion and insertion mixed together with a very
850 few lines that happen to match textually as the context, but as a
851 single deletion of everything old followed by a single insertion of
852 everything new, and the number <tt>m</tt> controls this aspect of the -B
853 option (defaults to 60%). <tt>-B/70%</tt> specifies that less than 30% of the
854 original should remain in the result for git to consider it a total
855 rewrite (i.e. otherwise the resulting patch will be a series of
856 deletion and insertion mixed together with context lines).</p></div>
857 <div class="paragraph
"><p>When used with -M, a totally-rewritten file is also considered as the
858 source of a rename (usually -M only considers a file that disappeared
859 as the source of a rename), and the number <tt>n</tt> controls this aspect of
860 the -B option (defaults to 50%). <tt>-B20%</tt> specifies that a change with
861 addition and deletion compared to 20% or more of the file’s size are
862 eligible for being picked up as a possible source of a rename to
863 another file.</p></div>
869 --find-renames[=<n>]
874 If <tt>n</tt> is specified, it is a is a threshold on the similarity
875 index (i.e. amount of addition/deletions compared to the
876 file’s size). For example, <tt>-M90%</tt> means git should consider a
877 delete/add pair to be a rename if more than 90% of the file
878 hasn’t changed.
885 --find-copies[=<n>]
889 Detect copies as well as renames. See also <tt>--find-copies-harder</tt>.
890 If <tt>n</tt> is specified, it has the same meaning as for <tt>-M<n></tt>.
898 For performance reasons, by default, <tt>-C</tt> option finds copies only
899 if the original file of the copy was modified in the same
900 changeset. This flag makes the command
901 inspect unmodified files as candidates for the source of
902 copy. This is a very expensive operation for large
903 projects, so use it with caution. Giving more than one
904 <tt>-C</tt> option has the same effect.
912 The <tt>-M</tt> and <tt>-C</tt> options require O(n^2) processing time where n
913 is the number of potential rename/copy targets. This
914 option prevents rename/copy detection from running if
915 the number of rename/copy targets exceeds the specified
920 --diff-filter=[(A|C|D|M|R|T|U|X|B)…[*]]
924 Select only files that are Added (<tt>A</tt>), Copied (<tt>C</tt>),
925 Deleted (<tt>D</tt>), Modified (<tt>M</tt>), Renamed (<tt>R</tt>), have their
926 type (i.e. regular file, symlink, submodule, …) changed (<tt>T</tt>),
927 are Unmerged (<tt>U</tt>), are
928 Unknown (<tt>X</tt>), or have had their pairing Broken (<tt>B</tt>).
929 Any combination of the filter characters (including none) can be used.
930 When <tt>*</tt> (All-or-none) is added to the combination, all
931 paths are selected if there is any file that matches
932 other criteria in the comparison; if there is no file
933 that matches other criteria, nothing is selected.
941 Look for differences that introduce or remove an instance of
942 <string>. Note that this is different than the string simply
943 appearing in diff output; see the <em>pickaxe</em> entry in
944 <a href="gitdiffcore.html
">gitdiffcore(7)</a> for more details.
952 Look for differences whose added or removed line matches
953 the given <regex>.
961 When <tt>-S</tt> or <tt>-G</tt> finds a change, show all the changes in that
962 changeset, not just the files that contain the change
971 Make the <string> not a plain string but an extended POSIX
980 Output the patch in the order specified in the
981 <orderfile>, which has one shell glob pattern per line.
989 Swap two inputs; that is, show differences from index or
990 on-disk file to tree contents.
994 --relative[=<path>]
998 When run from a subdirectory of the project, it can be
999 told to exclude changes outside the directory and show
1000 pathnames relative to it with this option. When you are
1001 not in a subdirectory (e.g. in a bare repository), you
1002 can name which subdirectory to make the output relative
1003 to by giving a <path> as an argument.
1006 <dt class="hdlist1
">
1009 <dt class="hdlist1
">
1014 Treat all files as text.
1017 <dt class="hdlist1
">
1018 --ignore-space-at-eol
1022 Ignore changes in whitespace at EOL.
1025 <dt class="hdlist1
">
1028 <dt class="hdlist1
">
1029 --ignore-space-change
1033 Ignore changes in amount of whitespace. This ignores whitespace
1034 at line end, and considers all other sequences of one or
1035 more whitespace characters to be equivalent.
1038 <dt class="hdlist1
">
1041 <dt class="hdlist1
">
1046 Ignore whitespace when comparing lines. This ignores
1047 differences even if one line has whitespace where the other
1051 <dt class="hdlist1
">
1052 --inter-hunk-context=<lines>
1056 Show the context between diff hunks, up to the specified number
1057 of lines, thereby fusing hunks that are close to each other.
1060 <dt class="hdlist1
">
1065 Make the program exit with codes similar to diff(1).
1066 That is, it exits with 1 if there were differences and
1067 0 means no differences.
1070 <dt class="hdlist1
">
1075 Disable all output of the program. Implies <tt>--exit-code</tt>.
1078 <dt class="hdlist1
">
1083 Allow an external diff helper to be executed. If you set an
1084 external diff driver with <a href="gitattributes.html
">gitattributes(5)</a>, you need
1085 to use this option with <a href="git-log.html
">git-log(1)</a> and friends.
1088 <dt class="hdlist1
">
1093 Disallow external diff drivers.
1096 <dt class="hdlist1
">
1097 --ignore-submodules[=<when>]
1101 Ignore changes to submodules in the diff generation. <when> can be
1102 either "none
", "untracked
", "dirty
" or "all
", which is the default
1103 Using "none
" will consider the submodule modified when it either contains
1104 untracked or modified files or its HEAD differs from the commit recorded
1105 in the superproject and can be used to override any settings of the
1106 <em>ignore</em> option in <a href="git-config.html
">git-config(1)</a> or <a href="gitmodules.html
">gitmodules(5)</a>. When
1107 "untracked
" is used submodules are not considered dirty when they only
1108 contain untracked content (but they are still scanned for modified
1109 content). Using "dirty
" ignores all changes to the work tree of submodules,
1110 only changes to the commits stored in the superproject are shown (this was
1111 the behavior until 1.7.0). Using "all
" hides all changes to submodules.
1114 <dt class="hdlist1
">
1115 --src-prefix=<prefix>
1119 Show the given source prefix instead of "a/
".
1122 <dt class="hdlist1
">
1123 --dst-prefix=<prefix>
1127 Show the given destination prefix instead of "b/
".
1130 <dt class="hdlist1
">
1135 Do not show any source or destination prefix.
1139 <div class="paragraph
"><p>For more detailed explanation on these common options, see also
1140 <a href="gitdiffcore.html
">gitdiffcore(7)</a>.</p></div>
1141 <div class="dlist
"><dl>
1142 <dt class="hdlist1
">
1147 The <paths> parameters, when given, are used to limit
1148 the diff to the named paths (you can give directory
1149 names and get diff for all files under them).
1154 <h2 id="_raw_output_format
">Raw output format</h2>
1155 <div class="sectionbody
">
1156 <div class="paragraph
"><p>The raw output format from "git-diff-index
", "git-diff-tree
",
1157 "git-diff-files
" and "git diff --raw
" are very similar.</p></div>
1158 <div class="paragraph
"><p>These commands all compare two sets of things; what is
1159 compared differs:</p></div>
1160 <div class="dlist
"><dl>
1161 <dt class="hdlist1
">
1162 git-diff-index <tree-ish>
1166 compares the <tree-ish> and the files on the filesystem.
1169 <dt class="hdlist1
">
1170 git-diff-index --cached <tree-ish>
1174 compares the <tree-ish> and the index.
1177 <dt class="hdlist1
">
1178 git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>…]
1182 compares the trees named by the two arguments.
1185 <dt class="hdlist1
">
1186 git-diff-files [<pattern>…]
1190 compares the index and the files on the filesystem.
1194 <div class="paragraph
"><p>The "git-diff-tree
" command begins its output by printing the hash of
1195 what is being compared. After that, all the commands print one output
1196 line per changed file.</p></div>
1197 <div class="paragraph
"><p>An output line is formatted this way:</p></div>
1198 <div class="listingblock
">
1199 <div class="content
">
1200 <pre><tt>in-place edit :100644 100644 bcd1234... 0123456... M file0
1201 copy-edit :100644 100644 abcd123... 1234567... C68 file1 file2
1202 rename-edit :100644 100644 abcd123... 1234567... R86 file1 file3
1203 create :000000 100644 0000000... 1234567... A file4
1204 delete :100644 000000 1234567... 0000000... D file5
1205 unmerged :000000 000000 0000000... 0000000... U file6</tt></pre>
1207 <div class="paragraph
"><p>That is, from the left to the right:</p></div>
1208 <div class="olist arabic
"><ol class="arabic
">
1216 mode for "src
"; 000000 if creation or unmerged.
1226 mode for "dst
"; 000000 if deletion or unmerged.
1236 sha1 for "src
"; 0{40} if creation or unmerged.
1246 sha1 for "dst
"; 0{40} if creation, unmerged or "look at work tree
".
1256 status, followed by optional "score
" number.
1261 a tab or a NUL when <em>-z</em> option is used.
1271 a tab or a NUL when <em>-z</em> option is used; only exists for C or R.
1276 path for "dst
"; only exists for C or R.
1281 an LF or a NUL when <em>-z</em> option is used, to terminate the record.
1285 <div class="paragraph
"><p>Possible status letters are:</p></div>
1286 <div class="ulist
"><ul>
1289 A: addition of a file
1294 C: copy of a file into a new one
1299 D: deletion of a file
1304 M: modification of the contents or mode of a file
1309 R: renaming of a file
1314 T: change in the type of the file
1319 U: file is unmerged (you must complete the merge before it can
1325 X: "unknown
" change type (most probably a bug, please report it)
1329 <div class="paragraph
"><p>Status letters C and R are always followed by a score (denoting the
1330 percentage of similarity between the source and target of the move or
1331 copy), and are the only ones to be so.</p></div>
1332 <div class="paragraph
"><p><sha1> is shown as all 0’s if a file is new on the filesystem
1333 and it is out of sync with the index.</p></div>
1334 <div class="paragraph
"><p>Example:</p></div>
1335 <div class="listingblock
">
1336 <div class="content
">
1337 <pre><tt>:100644 100644 5be4a4...... 000000...... M file.c</tt></pre>
1339 <div class="paragraph
"><p>When <tt>-z</tt> option is not used, TAB, LF, and backslash characters
1340 in pathnames are represented as <tt>\t</tt>, <tt>\n</tt>, and <tt>\\</tt>,
1341 respectively.</p></div>
1343 <h2 id="_diff_format_for_merges
">diff format for merges</h2>
1344 <div class="sectionbody
">
1345 <div class="paragraph
"><p>"git-diff-tree
", "git-diff-files
" and "git-diff --raw
"
1346 can take <em>-c</em> or <em>--cc</em> option
1347 to generate diff output also for merge commits. The output differs
1348 from the format described above in the following way:</p></div>
1349 <div class="olist arabic
"><ol class="arabic
">
1352 there is a colon for each parent
1357 there are more "src
" modes and "src
" sha1
1362 status is concatenated status characters for each parent
1367 no optional "score
" number
1372 single path, only for "dst
"
1376 <div class="paragraph
"><p>Example:</p></div>
1377 <div class="listingblock
">
1378 <div class="content
">
1379 <pre><tt>::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM describe.c</tt></pre>
1381 <div class="paragraph
"><p>Note that <em>combined diff</em> lists only files which were modified from
1382 all parents.</p></div>
1384 <h2 id="_generating_patches_with_p
">Generating patches with -p</h2>
1385 <div class="sectionbody
">
1386 <div class="paragraph
"><p>When "git-diff-index
", "git-diff-tree
", or "git-diff-files
" are run
1387 with a <em>-p</em> option, "git diff
" without the <em>--raw</em> option, or
1388 "git log
" with the "-p
" option, they
1389 do not produce the output described above; instead they produce a
1390 patch file. You can customize the creation of such patches via the
1391 GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables.</p></div>
1392 <div class="paragraph
"><p>What the -p option produces is slightly different from the traditional
1393 diff format:</p></div>
1394 <div class="olist arabic
"><ol class="arabic
">
1397 It is preceded with a "git diff
" header that looks like this:
1399 <div class="literalblock
">
1400 <div class="content
">
1401 <pre><tt>diff --git a/file1 b/file2</tt></pre>
1403 <div class="paragraph
"><p>The <tt>a/</tt> and <tt>b/</tt> filenames are the same unless rename/copy is
1404 involved. Especially, even for a creation or a deletion,
1405 <tt>/dev/null</tt> is <em>not</em> used in place of the <tt>a/</tt> or <tt>b/</tt> filenames.</p></div>
1406 <div class="paragraph
"><p>When rename/copy is involved, <tt>file1</tt> and <tt>file2</tt> show the
1407 name of the source file of the rename/copy and the name of
1408 the file that rename/copy produces, respectively.</p></div>
1412 It is followed by one or more extended header lines:
1414 <div class="literalblock
">
1415 <div class="content
">
1416 <pre><tt>old mode <mode>
1417 new mode <mode>
1418 deleted file mode <mode>
1419 new file mode <mode>
1420 copy from <path>
1421 copy to <path>
1422 rename from <path>
1423 rename to <path>
1424 similarity index <number>
1425 dissimilarity index <number>
1426 index <hash>..<hash> <mode></tt></pre>
1428 <div class="paragraph
"><p>File modes are printed as 6-digit octal numbers including the file type
1429 and file permission bits.</p></div>
1430 <div class="paragraph
"><p>Path names in extended headers do not include the <tt>a/</tt> and <tt>b/</tt> prefixes.</p></div>
1431 <div class="paragraph
"><p>The similarity index is the percentage of unchanged lines, and
1432 the dissimilarity index is the percentage of changed lines. It
1433 is a rounded down integer, followed by a percent sign. The
1434 similarity index value of 100% is thus reserved for two equal
1435 files, while 100% dissimilarity means that no line from the old
1436 file made it into the new one.</p></div>
1437 <div class="paragraph
"><p>The index line includes the SHA-1 checksum before and after the change.
1438 The <mode> is included if the file mode does not change; otherwise,
1439 separate lines indicate the old and the new mode.</p></div>
1443 TAB, LF, double quote and backslash characters in pathnames
1444 are represented as <tt>\t</tt>, <tt>\n</tt>, <tt>\"</tt> and
<tt>\\
</tt>, respectively.
1445 If there is need for such substitution then the whole
1446 pathname is put in double quotes.
1451 All the
<tt>file1
</tt> files in the output refer to files before the
1452 commit, and all the
<tt>file2
</tt> files refer to files after the commit.
1453 It is incorrect to apply each change to each file sequentially. For
1454 example, this patch will swap a and b:
1456 <div class=
"literalblock">
1457 <div class=
"content">
1458 <pre><tt>diff --git a/a b/b
1463 rename to a
</tt></pre>
1468 <h2 id=
"_combined_diff_format">combined diff format
</h2>
1469 <div class=
"sectionbody">
1470 <div class=
"paragraph"><p>"git-diff-tree",
"git-diff-files" and
"git-diff" can take
<em>-c
</em> or
1471 <em>--cc
</em> option to produce
<em>combined diff
</em>. For showing a merge commit
1472 with
"git log -p", this is the default format; you can force showing
1473 full diff with the
<em>-m
</em> option.
1474 A
<em>combined diff
</em> format looks like this:
</p></div>
1475 <div class=
"listingblock">
1476 <div class=
"content">
1477 <pre><tt>diff --combined describe.c
1478 index fabadb8,cc95eb0.
.4866510
1481 @@@ -
98,
20 -
98,
12 +
98,
20 @@@
1482 return (a_date
> b_date) ? -
1 : (a_date == b_date) ?
0 :
1;
1485 - static void describe(char *arg)
1486 -static void describe(struct commit *cmit, int last_one)
1487 ++static void describe(char *arg, int last_one)
1489 + unsigned char sha1[
20];
1490 + struct commit *cmit;
1491 struct commit_list *list;
1492 static int initialized =
0;
1493 struct commit_name *n;
1495 + if (get_sha1(arg, sha1)
< 0)
1496 + usage(describe_usage);
1497 + cmit = lookup_commit_reference(sha1);
1499 + usage(describe_usage);
1503 for_each_ref(get_name);
</tt></pre>
1505 <div class=
"olist arabic"><ol class=
"arabic">
1508 It is preceded with a
"git diff" header, that looks like
1509 this (when
<em>-c
</em> option is used):
1511 <div class=
"literalblock">
1512 <div class=
"content">
1513 <pre><tt>diff --combined file
</tt></pre>
1515 <div class=
"paragraph"><p>or like this (when
<em>--cc
</em> option is used):
</p></div>
1516 <div class=
"literalblock">
1517 <div class=
"content">
1518 <pre><tt>diff --cc file
</tt></pre>
1523 It is followed by one or more extended header lines
1524 (this example shows a merge with two parents):
1526 <div class=
"literalblock">
1527 <div class=
"content">
1528 <pre><tt>index
<hash
>,
<hash
>..
<hash
>
1529 mode
<mode
>,
<mode
>..
<mode
>
1530 new file mode
<mode
>
1531 deleted file mode
<mode
>,
<mode
></tt></pre>
1533 <div class=
"paragraph"><p>The
<tt>mode
<mode
>,
<mode
>..
<mode
></tt> line appears only if at least one of
1534 the
<mode
> is different from the rest. Extended headers with
1535 information about detected contents movement (renames and
1536 copying detection) are designed to work with diff of two
1537 <tree-ish
> and are not used by combined diff format.
</p></div>
1541 It is followed by two-line from-file/to-file header
1543 <div class=
"literalblock">
1544 <div class=
"content">
1546 +++ b/file
</tt></pre>
1548 <div class=
"paragraph"><p>Similar to two-line header for traditional
<em>unified
</em> diff
1549 format,
<tt>/dev/null
</tt> is used to signal created or deleted
1554 Chunk header format is modified to prevent people from
1555 accidentally feeding it to
<tt>patch -p1
</tt>. Combined diff format
1556 was created for review of merge commit changes, and was not
1557 meant for apply. The change is similar to the change in the
1558 extended
<em>index
</em> header:
1560 <div class=
"literalblock">
1561 <div class=
"content">
1562 <pre><tt>@@@
<from-file-range
> <from-file-range
> <to-file-range
> @@@
</tt></pre>
1564 <div class=
"paragraph"><p>There are (number of parents +
1)
<tt>@
</tt> characters in the chunk
1565 header for combined diff format.
</p></div>
1568 <div class=
"paragraph"><p>Unlike the traditional
<em>unified
</em> diff format, which shows two
1569 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
1570 added to B), or
<tt>" "</tt> (space
 — unchanged) prefix, this format
1571 compares two or more files file1, file2,
… with one file X, and
1572 shows how X differs from each of fileN. One column for each of
1573 fileN is prepended to the output line to note how X
’s line is
1574 different from it.
</p></div>
1575 <div class=
"paragraph"><p>A
<tt>-
</tt> character in the column N means that the line appears in
1576 fileN but it does not appear in the result. A
<tt>+
</tt> character
1577 in the column N means that the line appears in the result,
1578 and fileN does not have that line (in other words, the line was
1579 added, from the point of view of that parent).
</p></div>
1580 <div class=
"paragraph"><p>In the above example output, the function signature was changed
1581 from both files (hence two
<tt>-
</tt> removals from both file1 and
1582 file2, plus
<tt>++
</tt> to mean one line that was added does not appear
1583 in either file1 nor file2). Also eight other lines are the same
1584 from file1 but do not appear in file2 (hence prefixed with
<tt>+</tt>).
</p></div>
1585 <div class=
"paragraph"><p>When shown by
<tt>git diff-tree -c
</tt>, it compares the parents of a
1586 merge commit with the merge result (i.e. file1..fileN are the
1587 parents). When shown by
<tt>git diff-files -c
</tt>, it compares the
1588 two unresolved merge parents with the working tree file
1589 (i.e. file1 is stage
2 aka
"our version", file2 is stage
3 aka
1590 "their version").
</p></div>
1592 <h2 id=
"_other_diff_formats">other diff formats
</h2>
1593 <div class=
"sectionbody">
1594 <div class=
"paragraph"><p>The
<tt>--summary
</tt> option describes newly added, deleted, renamed and
1595 copied files. The
<tt>--stat
</tt> option adds diffstat(
1) graph to the
1596 output. These options can be combined with other options, such as
1597 <tt>-p
</tt>, and are meant for human consumption.
</p></div>
1598 <div class=
"paragraph"><p>When showing a change that involves a rename or a copy,
<tt>--stat
</tt> output
1599 formats the pathnames compactly by combining common prefix and suffix of
1600 the pathnames. For example, a change that moves
<tt>arch/i386/Makefile
</tt> to
1601 <tt>arch/x86/Makefile
</tt> while modifying
4 lines will be shown like this:
</p></div>
1602 <div class=
"listingblock">
1603 <div class=
"content">
1604 <pre><tt>arch/{i386 =
> x86}/Makefile |
4 +--
</tt></pre>
1606 <div class=
"paragraph"><p>The
<tt>--numstat
</tt> option gives the diffstat(
1) information but is designed
1607 for easier machine consumption. An entry in
<tt>--numstat
</tt> output looks
1608 like this:
</p></div>
1609 <div class=
"listingblock">
1610 <div class=
"content">
1612 3 1 arch/{i386 =
> x86}/Makefile
</tt></pre>
1614 <div class=
"paragraph"><p>That is, from left to right:
</p></div>
1615 <div class=
"olist arabic"><ol class=
"arabic">
1618 the number of added lines;
1628 the number of deleted lines;
1638 pathname (possibly with rename/copy information);
1647 <div class=
"paragraph"><p>When
<tt>-z
</tt> output option is in effect, the output is formatted this way:
</p></div>
1648 <div class=
"listingblock">
1649 <div class=
"content">
1650 <pre><tt>1 2 README NUL
1651 3 1 NUL arch/i386/Makefile NUL arch/x86/Makefile NUL
</tt></pre>
1653 <div class=
"paragraph"><p>That is:
</p></div>
1654 <div class=
"olist arabic"><ol class=
"arabic">
1657 the number of added lines;
1667 the number of deleted lines;
1677 a NUL (only exists if renamed/copied);
1682 pathname in preimage;
1687 a NUL (only exists if renamed/copied);
1692 pathname in postimage (only exists if renamed/copied);
1701 <div class=
"paragraph"><p>The extra
<tt>NUL
</tt> before the preimage path in renamed case is to allow
1702 scripts that read the output to tell if the current record being read is
1703 a single-path record or a rename/copy record without reading ahead.
1704 After reading added and deleted lines, reading up to
<tt>NUL
</tt> would yield
1705 the pathname, but if that is
<tt>NUL
</tt>, the record will show two paths.
</p></div>
1707 <h2 id=
"_examples">EXAMPLES
</h2>
1708 <div class=
"sectionbody">
1709 <div class=
"dlist"><dl>
1710 <dt class=
"hdlist1">
1711 Various ways to check your working tree
1714 <div class=
"listingblock">
1715 <div class=
"content">
1716 <pre><tt>$ git diff
<b><1></b>
1717 $ git diff --cached
<b><2></b>
1718 $ git diff HEAD
<b><3></b></tt></pre>
1720 <div class=
"colist arabic"><ol>
1723 Changes in the working tree not yet staged for the next commit.
1728 Changes between the index and your last commit; what you
1729 would be committing if you run
"git commit" without
"-a" option.
1734 Changes in the working tree since your last commit; what you
1735 would be committing if you run
"git commit -a"
1740 <dt class=
"hdlist1">
1741 Comparing with arbitrary commits
1744 <div class=
"listingblock">
1745 <div class=
"content">
1746 <pre><tt>$ git diff test
<b><1></b>
1747 $ git diff HEAD -- ./test
<b><2></b>
1748 $ git diff HEAD^ HEAD
<b><3></b></tt></pre>
1750 <div class=
"colist arabic"><ol>
1753 Instead of using the tip of the current branch, compare with the
1754 tip of
"test" branch.
1759 Instead of comparing with the tip of
"test" branch, compare with
1760 the tip of the current branch, but limit the comparison to the
1766 Compare the version before the last commit and the last commit.
1771 <dt class=
"hdlist1">
1775 <div class=
"listingblock">
1776 <div class=
"content">
1777 <pre><tt>$ git diff topic master
<b><1></b>
1778 $ git diff topic..master
<b><2></b>
1779 $ git diff topic...master
<b><3></b></tt></pre>
1781 <div class=
"colist arabic"><ol>
1784 Changes between the tips of the topic and the master branches.
1794 Changes that occurred on the master branch since when the topic
1795 branch was started off it.
1800 <dt class=
"hdlist1">
1801 Limiting the diff output
1804 <div class=
"listingblock">
1805 <div class=
"content">
1806 <pre><tt>$ git diff --diff-filter=MRC
<b><1></b>
1807 $ git diff --name-status
<b><2></b>
1808 $ git diff arch/i386 include/asm-i386
<b><3></b></tt></pre>
1810 <div class=
"colist arabic"><ol>
1813 Show only modification, rename and copy, but not addition
1819 Show only names and the nature of change, but not actual
1825 Limit diff output to named subtrees.
1830 <dt class=
"hdlist1">
1831 Munging the diff output
1834 <div class=
"listingblock">
1835 <div class=
"content">
1836 <pre><tt>$ git diff --find-copies-harder -B -C
<b><1></b>
1837 $ git diff -R
<b><2></b></tt></pre>
1839 <div class=
"colist arabic"><ol>
1842 Spend extra cycles to find renames, copies and complete
1843 rewrites (very expensive).
1848 Output diff in reverse.
1855 <h2 id=
"_see_also">SEE ALSO
</h2>
1856 <div class=
"sectionbody">
1857 <div class=
"paragraph"><p>diff(
1),
1858 <a href=
"git-difftool.html">git-difftool(
1)
</a>,
1859 <a href=
"git-log.html">git-log(
1)
</a>,
1860 <a href=
"gitdiffcore.html">gitdiffcore(
7)
</a>,
1861 <a href=
"git-format-patch.html">git-format-patch(
1)
</a>,
1862 <a href=
"git-apply.html">git-apply(
1)
</a></p></div>
1864 <h2 id=
"_author">Author
</h2>
1865 <div class=
"sectionbody">
1866 <div class=
"paragraph"><p>Written by Linus Torvalds
<<a href=
"mailto:torvalds@osdl.org">torvalds@osdl.org
</a>></p></div>
1868 <h2 id=
"_documentation">Documentation
</h2>
1869 <div class=
"sectionbody">
1870 <div class=
"paragraph"><p>Documentation by Junio C Hamano and the git-list
<<a href=
"mailto:git@vger.kernel.org">git@vger.kernel.org
</a>>.
</p></div>
1872 <h2 id=
"_git">GIT
</h2>
1873 <div class=
"sectionbody">
1874 <div class=
"paragraph"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
1877 <div id=
"footer-text">
1878 Last updated
2010-
12-
05 06:
20:
21 UTC