Autogenerated HTML docs for v1.7.0.3-291-g5e4f
[git/jnareb-git.git] / git-diff.html
blob2c80b0343d554ee39857f6f41ab7858fb4507486
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">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <meta name="generator" content="AsciiDoc 8.2.5" />
7 <style type="text/css">
8 /* Debug borders */
9 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
11 border: 1px solid red;
15 body {
16 margin: 1em 5% 1em 5%;
19 a {
20 color: blue;
21 text-decoration: underline;
23 a:visited {
24 color: fuchsia;
27 em {
28 font-style: italic;
31 strong {
32 font-weight: bold;
35 tt {
36 color: navy;
39 h1, h2, h3, h4, h5, h6 {
40 color: #527bbd;
41 font-family: sans-serif;
42 margin-top: 1.2em;
43 margin-bottom: 0.5em;
44 line-height: 1.3;
47 h1, h2, h3 {
48 border-bottom: 2px solid silver;
50 h2 {
51 padding-top: 0.5em;
53 h3 {
54 float: left;
56 h3 + * {
57 clear: left;
60 div.sectionbody {
61 font-family: serif;
62 margin-left: 0;
65 hr {
66 border: 1px solid silver;
69 p {
70 margin-top: 0.5em;
71 margin-bottom: 0.5em;
74 pre {
75 padding: 0;
76 margin: 0;
79 span#author {
80 color: #527bbd;
81 font-family: sans-serif;
82 font-weight: bold;
83 font-size: 1.1em;
85 span#email {
87 span#revision {
88 font-family: sans-serif;
91 div#footer {
92 font-family: sans-serif;
93 font-size: small;
94 border-top: 2px solid silver;
95 padding-top: 0.5em;
96 margin-top: 4.0em;
98 div#footer-text {
99 float: left;
100 padding-bottom: 0.5em;
102 div#footer-badges {
103 float: right;
104 padding-bottom: 0.5em;
107 div#preamble,
108 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
109 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
110 div.admonitionblock {
111 margin-right: 10%;
112 margin-top: 1.5em;
113 margin-bottom: 1.5em;
115 div.admonitionblock {
116 margin-top: 2.5em;
117 margin-bottom: 2.5em;
120 div.content { /* Block element content. */
121 padding: 0;
124 /* Block element titles. */
125 div.title, caption.title {
126 font-family: sans-serif;
127 font-weight: bold;
128 text-align: left;
129 margin-top: 1.0em;
130 margin-bottom: 0.5em;
132 div.title + * {
133 margin-top: 0;
136 td div.title:first-child {
137 margin-top: 0.0em;
139 div.content div.title:first-child {
140 margin-top: 0.0em;
142 div.content + div.title {
143 margin-top: 0.0em;
146 div.sidebarblock > div.content {
147 background: #ffffee;
148 border: 1px solid silver;
149 padding: 0.5em;
152 div.listingblock {
153 margin-right: 0%;
155 div.listingblock > div.content {
156 border: 1px solid silver;
157 background: #f4f4f4;
158 padding: 0.5em;
161 div.quoteblock > div.content {
162 padding-left: 2.0em;
165 div.attribution {
166 text-align: right;
168 div.verseblock + div.attribution {
169 text-align: left;
172 div.admonitionblock .icon {
173 vertical-align: top;
174 font-size: 1.1em;
175 font-weight: bold;
176 text-decoration: underline;
177 color: #527bbd;
178 padding-right: 0.5em;
180 div.admonitionblock td.content {
181 padding-left: 0.5em;
182 border-left: 2px solid silver;
185 div.exampleblock > div.content {
186 border-left: 2px solid silver;
187 padding: 0.5em;
190 div.verseblock div.content {
191 white-space: pre;
194 div.imageblock div.content { padding-left: 0; }
195 div.imageblock img { border: 1px solid silver; }
196 span.image img { border-style: none; }
198 dl {
199 margin-top: 0.8em;
200 margin-bottom: 0.8em;
202 dt {
203 margin-top: 0.5em;
204 margin-bottom: 0;
205 font-style: italic;
207 dd > *:first-child {
208 margin-top: 0;
211 ul, ol {
212 list-style-position: outside;
214 div.olist2 ol {
215 list-style-type: lower-alpha;
218 div.tableblock > table {
219 border: 3px solid #527bbd;
221 thead {
222 font-family: sans-serif;
223 font-weight: bold;
225 tfoot {
226 font-weight: bold;
229 div.hlist {
230 margin-top: 0.8em;
231 margin-bottom: 0.8em;
233 div.hlist td {
234 padding-bottom: 5px;
236 td.hlist1 {
237 vertical-align: top;
238 font-style: italic;
239 padding-right: 0.8em;
241 td.hlist2 {
242 vertical-align: top;
245 @media print {
246 div#footer-badges { display: none; }
249 div#toctitle {
250 color: #527bbd;
251 font-family: sans-serif;
252 font-size: 1.1em;
253 font-weight: bold;
254 margin-top: 1.0em;
255 margin-bottom: 0.1em;
258 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
259 margin-top: 0;
260 margin-bottom: 0;
262 div.toclevel2 {
263 margin-left: 2em;
264 font-size: 0.9em;
266 div.toclevel3 {
267 margin-left: 4em;
268 font-size: 0.9em;
270 div.toclevel4 {
271 margin-left: 6em;
272 font-size: 0.9em;
274 include1::./stylesheets/xhtml11-manpage.css[]
275 /* Workarounds for IE6's broken and incomplete CSS2. */
277 div.sidebar-content {
278 background: #ffffee;
279 border: 1px solid silver;
280 padding: 0.5em;
282 div.sidebar-title, div.image-title {
283 font-family: sans-serif;
284 font-weight: bold;
285 margin-top: 0.0em;
286 margin-bottom: 0.5em;
289 div.listingblock div.content {
290 border: 1px solid silver;
291 background: #f4f4f4;
292 padding: 0.5em;
295 div.quoteblock-content {
296 padding-left: 2.0em;
299 div.exampleblock-content {
300 border-left: 2px solid silver;
301 padding-left: 0.5em;
304 /* IE6 sets dynamically generated links as visited. */
305 div#toc a:visited { color: blue; }
306 </style>
307 <title>git-diff(1)</title>
308 </head>
309 <body>
310 <div id="header">
311 <h1>
312 git-diff(1) Manual Page
313 </h1>
314 <h2>NAME</h2>
315 <div class="sectionbody">
316 <p>git-diff -
317 Show changes between commits, commit and working tree, etc
318 </p>
319 </div>
320 </div>
321 <h2>SYNOPSIS</h2>
322 <div class="sectionbody">
323 <div class="para"><p><em>git diff</em> [&lt;common diff options&gt;] &lt;commit&gt;{0,2} [--] [&lt;path&gt;&#8230;]</p></div>
324 </div>
325 <h2 id="_description">DESCRIPTION</h2>
326 <div class="sectionbody">
327 <div class="para"><p>Show changes between two trees, a tree and the working tree, a
328 tree and the index file, or the index file and the working tree.</p></div>
329 <div class="vlist"><dl>
330 <dt>
331 <em>git diff</em> [--options] [--] [&lt;path&gt;&#8230;]
332 </dt>
333 <dd>
335 This form is to view the changes you made relative to
336 the index (staging area for the next commit). In other
337 words, the differences are what you _could_ tell git to
338 further add to the index but you still haven't. You can
339 stage these changes by using <a href="git-add.html">git-add(1)</a>.
340 </p>
341 <div class="para"><p>If exactly two paths are given, and at least one is untracked,
342 compare the two files / directories. This behavior can be
343 forced by --no-index.</p></div>
344 </dd>
345 <dt>
346 <em>git diff</em> [--options] --cached [&lt;commit&gt;] [--] [&lt;path&gt;&#8230;]
347 </dt>
348 <dd>
350 This form is to view the changes you staged for the next
351 commit relative to the named &lt;commit&gt;. Typically you
352 would want comparison with the latest commit, so if you
353 do not give &lt;commit&gt;, it defaults to HEAD.
354 --staged is a synonym of --cached.
355 </p>
356 </dd>
357 <dt>
358 <em>git diff</em> [--options] &lt;commit&gt; [--] [&lt;path&gt;&#8230;]
359 </dt>
360 <dd>
362 This form is to view the changes you have in your
363 working tree relative to the named &lt;commit&gt;. You can
364 use HEAD to compare it with the latest commit, or a
365 branch name to compare with the tip of a different
366 branch.
367 </p>
368 </dd>
369 <dt>
370 <em>git diff</em> [--options] &lt;commit&gt; &lt;commit&gt; [--] [&lt;path&gt;&#8230;]
371 </dt>
372 <dd>
374 This is to view the changes between two arbitrary
375 &lt;commit&gt;.
376 </p>
377 </dd>
378 <dt>
379 <em>git diff</em> [--options] &lt;commit&gt;..&lt;commit&gt; [--] [&lt;path&gt;&#8230;]
380 </dt>
381 <dd>
383 This is synonymous to the previous form. If &lt;commit&gt; on
384 one side is omitted, it will have the same effect as
385 using HEAD instead.
386 </p>
387 </dd>
388 <dt>
389 <em>git diff</em> [--options] &lt;commit&gt;...&lt;commit&gt; [--] [&lt;path&gt;&#8230;]
390 </dt>
391 <dd>
393 This form is to view the changes on the branch containing
394 and up to the second &lt;commit&gt;, starting at a common ancestor
395 of both &lt;commit&gt;. "git diff A...B" is equivalent to
396 "git diff $(git-merge-base A B) B". You can omit any one
397 of &lt;commit&gt;, which has the same effect as using HEAD instead.
398 </p>
399 </dd>
400 </dl></div>
401 <div class="para"><p>Just in case if you are doing something exotic, it should be
402 noted that all of the &lt;commit&gt; in the above description, except
403 for the last two forms that use ".." notations, can be any
404 &lt;tree-ish&gt;.</p></div>
405 <div class="para"><p>For a more complete list of ways to spell &lt;commit&gt;, see
406 "SPECIFYING REVISIONS" section in <a href="git-rev-parse.html">git-rev-parse(1)</a>.
407 However, "diff" is about comparing two _endpoints_, not ranges,
408 and the range notations ("&lt;commit&gt;..&lt;commit&gt;" and
409 "&lt;commit&gt;...&lt;commit&gt;") do not mean a range as defined in the
410 "SPECIFYING RANGES" section in <a href="git-rev-parse.html">git-rev-parse(1)</a>.</p></div>
411 </div>
412 <h2 id="_options">OPTIONS</h2>
413 <div class="sectionbody">
414 <div class="vlist"><dl>
415 <dt>
417 </dt>
418 <dt>
420 </dt>
421 <dd>
423 Generate patch (see section on generating patches).
424 This is the default.
425 </p>
426 </dd>
427 <dt>
428 -U&lt;n&gt;
429 </dt>
430 <dt>
431 --unified=&lt;n&gt;
432 </dt>
433 <dd>
435 Generate diffs with &lt;n&gt; lines of context instead of
436 the usual three.
437 Implies <tt>-p</tt>.
438 </p>
439 </dd>
440 <dt>
441 --raw
442 </dt>
443 <dd>
445 Generate the raw format.
447 </p>
448 </dd>
449 <dt>
450 --patch-with-raw
451 </dt>
452 <dd>
454 Synonym for <tt>-p --raw</tt>.
455 </p>
456 </dd>
457 <dt>
458 --patience
459 </dt>
460 <dd>
462 Generate a diff using the "patience diff" algorithm.
463 </p>
464 </dd>
465 <dt>
466 --stat[=width[,name-width]]
467 </dt>
468 <dd>
470 Generate a diffstat. You can override the default
471 output width for 80-column terminal by <tt>--stat=width</tt>.
472 The width of the filename part can be controlled by
473 giving another width to it separated by a comma.
474 </p>
475 </dd>
476 <dt>
477 --numstat
478 </dt>
479 <dd>
481 Similar to <tt>--stat</tt>, but shows number of added and
482 deleted lines in decimal notation and pathname without
483 abbreviation, to make it more machine friendly. For
484 binary files, outputs two <tt>-</tt> instead of saying
485 <tt>0 0</tt>.
486 </p>
487 </dd>
488 <dt>
489 --shortstat
490 </dt>
491 <dd>
493 Output only the last line of the <tt>--stat</tt> format containing total
494 number of modified files, as well as number of added and deleted
495 lines.
496 </p>
497 </dd>
498 <dt>
499 --dirstat[=limit]
500 </dt>
501 <dd>
503 Output the distribution of relative amount of changes (number of lines added or
504 removed) for each sub-directory. Directories with changes below
505 a cut-off percent (3% by default) are not shown. The cut-off percent
506 can be set with <tt>--dirstat=limit</tt>. Changes in a child directory is not
507 counted for the parent directory, unless <tt>--cumulative</tt> is used.
508 </p>
509 </dd>
510 <dt>
511 --dirstat-by-file[=limit]
512 </dt>
513 <dd>
515 Same as <tt>--dirstat</tt>, but counts changed files instead of lines.
516 </p>
517 </dd>
518 <dt>
519 --summary
520 </dt>
521 <dd>
523 Output a condensed summary of extended header information
524 such as creations, renames and mode changes.
525 </p>
526 </dd>
527 <dt>
528 --patch-with-stat
529 </dt>
530 <dd>
532 Synonym for <tt>-p --stat</tt>.
533 </p>
534 </dd>
535 <dt>
537 </dt>
538 <dd>
540 When <tt>--raw</tt> or <tt>--numstat</tt> has been given, do not munge
541 pathnames and use NULs as output field terminators.
542 </p>
543 <div class="para"><p>Without this option, each pathname output will have TAB, LF, double quotes,
544 and backslash characters replaced with <tt>\t</tt>, <tt>\n</tt>, <tt>\"</tt>, and <tt>\\</tt>,
545 respectively, and the pathname will be enclosed in double quotes if
546 any of those replacements occurred.</p></div>
547 </dd>
548 <dt>
549 --name-only
550 </dt>
551 <dd>
553 Show only names of changed files.
554 </p>
555 </dd>
556 <dt>
557 --name-status
558 </dt>
559 <dd>
561 Show only names and status of changed files. See the description
562 of the <tt>--diff-filter</tt> option on what the status letters mean.
563 </p>
564 </dd>
565 <dt>
566 --submodule[=&lt;format&gt;]
567 </dt>
568 <dd>
570 Chose the output format for submodule differences. &lt;format&gt; can be one of
571 <em>short</em> and <em>log</em>. <em>short</em> just shows pairs of commit names, this format
572 is used when this option is not given. <em>log</em> is the default value for this
573 option and lists the commits in that commit range like the <em>summary</em>
574 option of <a href="git-submodule.html">git-submodule(1)</a> does.
575 </p>
576 </dd>
577 <dt>
578 --color[=&lt;when&gt;]
579 </dt>
580 <dd>
582 Show colored diff.
583 The value must be always (the default), never, or auto.
584 </p>
585 </dd>
586 <dt>
587 --no-color
588 </dt>
589 <dd>
591 Turn off colored diff, even when the configuration file
592 gives the default to color output.
593 Same as <tt>--color=never</tt>.
594 </p>
595 </dd>
596 <dt>
597 --color-words[=&lt;regex&gt;]
598 </dt>
599 <dd>
601 Show colored word diff, i.e., color words which have changed.
602 By default, words are separated by whitespace.
603 </p>
604 <div class="para"><p>When a &lt;regex&gt; is specified, every non-overlapping match of the
605 &lt;regex&gt; is considered a word. Anything between these matches is
606 considered whitespace and ignored(!) for the purposes of finding
607 differences. You may want to append <tt>|[^[:space:]]</tt> to your regular
608 expression to make sure that it matches all non-whitespace characters.
609 A match that contains a newline is silently truncated(!) at the
610 newline.</p></div>
611 <div class="para"><p>The regex can also be set via a diff driver or configuration option, see
612 <a href="gitattributes.html">gitattributes(1)</a> or <a href="git-config.html">git-config(1)</a>. Giving it explicitly
613 overrides any diff driver or configuration setting. Diff drivers
614 override configuration settings.</p></div>
615 </dd>
616 <dt>
617 --no-renames
618 </dt>
619 <dd>
621 Turn off rename detection, even when the configuration
622 file gives the default to do so.
623 </p>
624 </dd>
625 <dt>
626 --check
627 </dt>
628 <dd>
630 Warn if changes introduce trailing whitespace
631 or an indent that uses a space before a tab. Exits with
632 non-zero status if problems are found. Not compatible with
633 --exit-code.
634 </p>
635 </dd>
636 <dt>
637 --full-index
638 </dt>
639 <dd>
641 Instead of the first handful of characters, show the full
642 pre- and post-image blob object names on the "index"
643 line when generating patch format output.
644 </p>
645 </dd>
646 <dt>
647 --binary
648 </dt>
649 <dd>
651 In addition to <tt>--full-index</tt>, output a binary diff that
652 can be applied with <tt>git-apply</tt>.
653 </p>
654 </dd>
655 <dt>
656 --abbrev[=&lt;n&gt;]
657 </dt>
658 <dd>
660 Instead of showing the full 40-byte hexadecimal object
661 name in diff-raw format output and diff-tree header
662 lines, show only a partial prefix. This is
663 independent of the <tt>--full-index</tt> option above, which controls
664 the diff-patch output format. Non default number of
665 digits can be specified with <tt>--abbrev=&lt;n&gt;</tt>.
666 </p>
667 </dd>
668 <dt>
670 </dt>
671 <dd>
673 Break complete rewrite changes into pairs of delete and create.
674 </p>
675 </dd>
676 <dt>
678 </dt>
679 <dd>
681 Detect renames.
682 </p>
683 </dd>
684 <dt>
686 </dt>
687 <dd>
689 Detect copies as well as renames. See also <tt>--find-copies-harder</tt>.
690 </p>
691 </dd>
692 <dt>
693 --diff-filter=[ACDMRTUXB*]
694 </dt>
695 <dd>
697 Select only files that are Added (<tt>A</tt>), Copied (<tt>C</tt>),
698 Deleted (<tt>D</tt>), Modified (<tt>M</tt>), Renamed (<tt>R</tt>), have their
699 type (i.e. regular file, symlink, submodule, &#8230;) changed (<tt>T</tt>),
700 are Unmerged (<tt>U</tt>), are
701 Unknown (<tt>X</tt>), or have had their pairing Broken (<tt>B</tt>).
702 Any combination of the filter characters may be used.
703 When <tt>*</tt> (All-or-none) is added to the combination, all
704 paths are selected if there is any file that matches
705 other criteria in the comparison; if there is no file
706 that matches other criteria, nothing is selected.
707 </p>
708 </dd>
709 <dt>
710 --find-copies-harder
711 </dt>
712 <dd>
714 For performance reasons, by default, <tt>-C</tt> option finds copies only
715 if the original file of the copy was modified in the same
716 changeset. This flag makes the command
717 inspect unmodified files as candidates for the source of
718 copy. This is a very expensive operation for large
719 projects, so use it with caution. Giving more than one
720 <tt>-C</tt> option has the same effect.
721 </p>
722 </dd>
723 <dt>
724 -l&lt;num&gt;
725 </dt>
726 <dd>
728 The <tt>-M</tt> and <tt>-C</tt> options require O(n^2) processing time where n
729 is the number of potential rename/copy targets. This
730 option prevents rename/copy detection from running if
731 the number of rename/copy targets exceeds the specified
732 number.
733 </p>
734 </dd>
735 <dt>
736 -S&lt;string&gt;
737 </dt>
738 <dd>
740 Look for differences that introduce or remove an instance of
741 &lt;string&gt;. Note that this is different than the string simply
742 appearing in diff output; see the <em>pickaxe</em> entry in
743 <a href="gitdiffcore.html">gitdiffcore(7)</a> for more details.
744 </p>
745 </dd>
746 <dt>
747 --pickaxe-all
748 </dt>
749 <dd>
751 When <tt>-S</tt> finds a change, show all the changes in that
752 changeset, not just the files that contain the change
753 in &lt;string&gt;.
754 </p>
755 </dd>
756 <dt>
757 --pickaxe-regex
758 </dt>
759 <dd>
761 Make the &lt;string&gt; not a plain string but an extended POSIX
762 regex to match.
763 </p>
764 </dd>
765 <dt>
766 -O&lt;orderfile&gt;
767 </dt>
768 <dd>
770 Output the patch in the order specified in the
771 &lt;orderfile&gt;, which has one shell glob pattern per line.
772 </p>
773 </dd>
774 <dt>
776 </dt>
777 <dd>
779 Swap two inputs; that is, show differences from index or
780 on-disk file to tree contents.
781 </p>
782 </dd>
783 <dt>
784 --relative[=&lt;path&gt;]
785 </dt>
786 <dd>
788 When run from a subdirectory of the project, it can be
789 told to exclude changes outside the directory and show
790 pathnames relative to it with this option. When you are
791 not in a subdirectory (e.g. in a bare repository), you
792 can name which subdirectory to make the output relative
793 to by giving a &lt;path&gt; as an argument.
794 </p>
795 </dd>
796 <dt>
798 </dt>
799 <dt>
800 --text
801 </dt>
802 <dd>
804 Treat all files as text.
805 </p>
806 </dd>
807 <dt>
808 --ignore-space-at-eol
809 </dt>
810 <dd>
812 Ignore changes in whitespace at EOL.
813 </p>
814 </dd>
815 <dt>
817 </dt>
818 <dt>
819 --ignore-space-change
820 </dt>
821 <dd>
823 Ignore changes in amount of whitespace. This ignores whitespace
824 at line end, and considers all other sequences of one or
825 more whitespace characters to be equivalent.
826 </p>
827 </dd>
828 <dt>
830 </dt>
831 <dt>
832 --ignore-all-space
833 </dt>
834 <dd>
836 Ignore whitespace when comparing lines. This ignores
837 differences even if one line has whitespace where the other
838 line has none.
839 </p>
840 </dd>
841 <dt>
842 --inter-hunk-context=&lt;lines&gt;
843 </dt>
844 <dd>
846 Show the context between diff hunks, up to the specified number
847 of lines, thereby fusing hunks that are close to each other.
848 </p>
849 </dd>
850 <dt>
851 --exit-code
852 </dt>
853 <dd>
855 Make the program exit with codes similar to diff(1).
856 That is, it exits with 1 if there were differences and
857 0 means no differences.
858 </p>
859 </dd>
860 <dt>
861 --quiet
862 </dt>
863 <dd>
865 Disable all output of the program. Implies <tt>--exit-code</tt>.
866 </p>
867 </dd>
868 <dt>
869 --ext-diff
870 </dt>
871 <dd>
873 Allow an external diff helper to be executed. If you set an
874 external diff driver with <a href="gitattributes.html">gitattributes(5)</a>, you need
875 to use this option with <a href="git-log.html">git-log(1)</a> and friends.
876 </p>
877 </dd>
878 <dt>
879 --no-ext-diff
880 </dt>
881 <dd>
883 Disallow external diff drivers.
884 </p>
885 </dd>
886 <dt>
887 --ignore-submodules
888 </dt>
889 <dd>
891 Ignore changes to submodules in the diff generation.
892 </p>
893 </dd>
894 <dt>
895 --src-prefix=&lt;prefix&gt;
896 </dt>
897 <dd>
899 Show the given source prefix instead of "a/".
900 </p>
901 </dd>
902 <dt>
903 --dst-prefix=&lt;prefix&gt;
904 </dt>
905 <dd>
907 Show the given destination prefix instead of "b/".
908 </p>
909 </dd>
910 <dt>
911 --no-prefix
912 </dt>
913 <dd>
915 Do not show any source or destination prefix.
916 </p>
917 </dd>
918 </dl></div>
919 <div class="para"><p>For more detailed explanation on these common options, see also
920 <a href="gitdiffcore.html">gitdiffcore(7)</a>.</p></div>
921 <div class="vlist"><dl>
922 <dt>
923 &lt;path&gt;&#8230;
924 </dt>
925 <dd>
927 The &lt;paths&gt; parameters, when given, are used to limit
928 the diff to the named paths (you can give directory
929 names and get diff for all files under them).
930 </p>
931 </dd>
932 </dl></div>
933 </div>
934 <h2 id="_raw_output_format">Raw output format</h2>
935 <div class="sectionbody">
936 <div class="para"><p>The raw output format from "git-diff-index", "git-diff-tree",
937 "git-diff-files" and "git diff --raw" are very similar.</p></div>
938 <div class="para"><p>These commands all compare two sets of things; what is
939 compared differs:</p></div>
940 <div class="vlist"><dl>
941 <dt>
942 git-diff-index &lt;tree-ish&gt;
943 </dt>
944 <dd>
946 compares the &lt;tree-ish&gt; and the files on the filesystem.
947 </p>
948 </dd>
949 <dt>
950 git-diff-index --cached &lt;tree-ish&gt;
951 </dt>
952 <dd>
954 compares the &lt;tree-ish&gt; and the index.
955 </p>
956 </dd>
957 <dt>
958 git-diff-tree [-r] &lt;tree-ish-1&gt; &lt;tree-ish-2&gt; [&lt;pattern&gt;&#8230;]
959 </dt>
960 <dd>
962 compares the trees named by the two arguments.
963 </p>
964 </dd>
965 <dt>
966 git-diff-files [&lt;pattern&gt;&#8230;]
967 </dt>
968 <dd>
970 compares the index and the files on the filesystem.
971 </p>
972 </dd>
973 </dl></div>
974 <div class="para"><p>The "git-diff-tree" command begins its output by printing the hash of
975 what is being compared. After that, all the commands print one output
976 line per changed file.</p></div>
977 <div class="para"><p>An output line is formatted this way:</p></div>
978 <div class="listingblock">
979 <div class="content">
980 <pre><tt>in-place edit :100644 100644 bcd1234... 0123456... M file0
981 copy-edit :100644 100644 abcd123... 1234567... C68 file1 file2
982 rename-edit :100644 100644 abcd123... 1234567... R86 file1 file3
983 create :000000 100644 0000000... 1234567... A file4
984 delete :100644 000000 1234567... 0000000... D file5
985 unmerged :000000 000000 0000000... 0000000... U file6</tt></pre>
986 </div></div>
987 <div class="para"><p>That is, from the left to the right:</p></div>
988 <div class="olist"><ol>
989 <li>
991 a colon.
992 </p>
993 </li>
994 <li>
996 mode for "src"; 000000 if creation or unmerged.
997 </p>
998 </li>
999 <li>
1001 a space.
1002 </p>
1003 </li>
1004 <li>
1006 mode for "dst"; 000000 if deletion or unmerged.
1007 </p>
1008 </li>
1009 <li>
1011 a space.
1012 </p>
1013 </li>
1014 <li>
1016 sha1 for "src"; 0{40} if creation or unmerged.
1017 </p>
1018 </li>
1019 <li>
1021 a space.
1022 </p>
1023 </li>
1024 <li>
1026 sha1 for "dst"; 0{40} if creation, unmerged or "look at work tree".
1027 </p>
1028 </li>
1029 <li>
1031 a space.
1032 </p>
1033 </li>
1034 <li>
1036 status, followed by optional "score" number.
1037 </p>
1038 </li>
1039 <li>
1041 a tab or a NUL when <em>-z</em> option is used.
1042 </p>
1043 </li>
1044 <li>
1046 path for "src"
1047 </p>
1048 </li>
1049 <li>
1051 a tab or a NUL when <em>-z</em> option is used; only exists for C or R.
1052 </p>
1053 </li>
1054 <li>
1056 path for "dst"; only exists for C or R.
1057 </p>
1058 </li>
1059 <li>
1061 an LF or a NUL when <em>-z</em> option is used, to terminate the record.
1062 </p>
1063 </li>
1064 </ol></div>
1065 <div class="para"><p>Possible status letters are:</p></div>
1066 <div class="ilist"><ul>
1067 <li>
1069 A: addition of a file
1070 </p>
1071 </li>
1072 <li>
1074 C: copy of a file into a new one
1075 </p>
1076 </li>
1077 <li>
1079 D: deletion of a file
1080 </p>
1081 </li>
1082 <li>
1084 M: modification of the contents or mode of a file
1085 </p>
1086 </li>
1087 <li>
1089 R: renaming of a file
1090 </p>
1091 </li>
1092 <li>
1094 T: change in the type of the file
1095 </p>
1096 </li>
1097 <li>
1099 U: file is unmerged (you must complete the merge before it can
1100 be committed)
1101 </p>
1102 </li>
1103 <li>
1105 X: "unknown" change type (most probably a bug, please report it)
1106 </p>
1107 </li>
1108 </ul></div>
1109 <div class="para"><p>Status letters C and R are always followed by a score (denoting the
1110 percentage of similarity between the source and target of the move or
1111 copy), and are the only ones to be so.</p></div>
1112 <div class="para"><p>&lt;sha1&gt; is shown as all 0's if a file is new on the filesystem
1113 and it is out of sync with the index.</p></div>
1114 <div class="para"><p>Example:</p></div>
1115 <div class="listingblock">
1116 <div class="content">
1117 <pre><tt>:100644 100644 5be4a4...... 000000...... M file.c</tt></pre>
1118 </div></div>
1119 <div class="para"><p>When <tt>-z</tt> option is not used, TAB, LF, and backslash characters
1120 in pathnames are represented as <tt>\t</tt>, <tt>\n</tt>, and <tt>\\</tt>,
1121 respectively.</p></div>
1122 </div>
1123 <h2 id="_diff_format_for_merges">diff format for merges</h2>
1124 <div class="sectionbody">
1125 <div class="para"><p>"git-diff-tree", "git-diff-files" and "git-diff --raw"
1126 can take <em>-c</em> or <em>--cc</em> option
1127 to generate diff output also for merge commits. The output differs
1128 from the format described above in the following way:</p></div>
1129 <div class="olist"><ol>
1130 <li>
1132 there is a colon for each parent
1133 </p>
1134 </li>
1135 <li>
1137 there are more "src" modes and "src" sha1
1138 </p>
1139 </li>
1140 <li>
1142 status is concatenated status characters for each parent
1143 </p>
1144 </li>
1145 <li>
1147 no optional "score" number
1148 </p>
1149 </li>
1150 <li>
1152 single path, only for "dst"
1153 </p>
1154 </li>
1155 </ol></div>
1156 <div class="para"><p>Example:</p></div>
1157 <div class="listingblock">
1158 <div class="content">
1159 <pre><tt>::100644 100644 100644 fabadb8... cc95eb0... 4866510... MM describe.c</tt></pre>
1160 </div></div>
1161 <div class="para"><p>Note that <em>combined diff</em> lists only files which were modified from
1162 all parents.</p></div>
1163 </div>
1164 <h2 id="_generating_patches_with_p">Generating patches with -p</h2>
1165 <div class="sectionbody">
1166 <div class="para"><p>When "git-diff-index", "git-diff-tree", or "git-diff-files" are run
1167 with a <em>-p</em> option, "git diff" without the <em>--raw</em> option, or
1168 "git log" with the "-p" option, they
1169 do not produce the output described above; instead they produce a
1170 patch file. You can customize the creation of such patches via the
1171 GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables.</p></div>
1172 <div class="para"><p>What the -p option produces is slightly different from the traditional
1173 diff format.</p></div>
1174 <div class="olist"><ol>
1175 <li>
1177 It is preceded with a "git diff" header, that looks like
1178 this:
1179 </p>
1180 <div class="literalblock">
1181 <div class="content">
1182 <pre><tt>diff --git a/file1 b/file2</tt></pre>
1183 </div></div>
1184 <div class="para"><p>The <tt>a/</tt> and <tt>b/</tt> filenames are the same unless rename/copy is
1185 involved. Especially, even for a creation or a deletion,
1186 <tt>/dev/null</tt> is _not_ used in place of <tt>a/</tt> or <tt>b/</tt> filenames.</p></div>
1187 <div class="para"><p>When rename/copy is involved, <tt>file1</tt> and <tt>file2</tt> show the
1188 name of the source file of the rename/copy and the name of
1189 the file that rename/copy produces, respectively.</p></div>
1190 </li>
1191 <li>
1193 It is followed by one or more extended header lines:
1194 </p>
1195 <div class="literalblock">
1196 <div class="content">
1197 <pre><tt>old mode &lt;mode&gt;
1198 new mode &lt;mode&gt;
1199 deleted file mode &lt;mode&gt;
1200 new file mode &lt;mode&gt;
1201 copy from &lt;path&gt;
1202 copy to &lt;path&gt;
1203 rename from &lt;path&gt;
1204 rename to &lt;path&gt;
1205 similarity index &lt;number&gt;
1206 dissimilarity index &lt;number&gt;
1207 index &lt;hash&gt;..&lt;hash&gt; &lt;mode&gt;</tt></pre>
1208 </div></div>
1209 </li>
1210 <li>
1212 TAB, LF, double quote and backslash characters in pathnames
1213 are represented as <tt>\t</tt>, <tt>\n</tt>, <tt>\"</tt> and <tt>\\</tt>, respectively.
1214 If there is need for such substitution then the whole
1215 pathname is put in double quotes.
1216 </p>
1217 </li>
1218 </ol></div>
1219 <div class="para"><p>The similarity index is the percentage of unchanged lines, and
1220 the dissimilarity index is the percentage of changed lines. It
1221 is a rounded down integer, followed by a percent sign. The
1222 similarity index value of 100% is thus reserved for two equal
1223 files, while 100% dissimilarity means that no line from the old
1224 file made it into the new one.</p></div>
1225 </div>
1226 <h2 id="_combined_diff_format">combined diff format</h2>
1227 <div class="sectionbody">
1228 <div class="para"><p>"git-diff-tree", "git-diff-files" and "git-diff" can take <em>-c</em> or
1229 <em>--cc</em> option to produce <em>combined diff</em>. For showing a merge commit
1230 with "git log -p", this is the default format; you can force showing
1231 full diff with the <em>-m</em> option.
1232 A <em>combined diff</em> format looks like this:</p></div>
1233 <div class="listingblock">
1234 <div class="content">
1235 <pre><tt>diff --combined describe.c
1236 index fabadb8,cc95eb0..4866510
1237 --- a/describe.c
1238 +++ b/describe.c
1239 @@@ -98,20 -98,12 +98,20 @@@
1240 return (a_date &gt; b_date) ? -1 : (a_date == b_date) ? 0 : 1;
1243 - static void describe(char *arg)
1244 -static void describe(struct commit *cmit, int last_one)
1245 ++static void describe(char *arg, int last_one)
1247 + unsigned char sha1[20];
1248 + struct commit *cmit;
1249 struct commit_list *list;
1250 static int initialized = 0;
1251 struct commit_name *n;
1253 + if (get_sha1(arg, sha1) &lt; 0)
1254 + usage(describe_usage);
1255 + cmit = lookup_commit_reference(sha1);
1256 + if (!cmit)
1257 + usage(describe_usage);
1259 if (!initialized) {
1260 initialized = 1;
1261 for_each_ref(get_name);</tt></pre>
1262 </div></div>
1263 <div class="olist"><ol>
1264 <li>
1266 It is preceded with a "git diff" header, that looks like
1267 this (when <em>-c</em> option is used):
1268 </p>
1269 <div class="literalblock">
1270 <div class="content">
1271 <pre><tt>diff --combined file</tt></pre>
1272 </div></div>
1273 <div class="para"><p>or like this (when <em>--cc</em> option is used):</p></div>
1274 <div class="literalblock">
1275 <div class="content">
1276 <pre><tt>diff --cc file</tt></pre>
1277 </div></div>
1278 </li>
1279 <li>
1281 It is followed by one or more extended header lines
1282 (this example shows a merge with two parents):
1283 </p>
1284 <div class="literalblock">
1285 <div class="content">
1286 <pre><tt>index &lt;hash&gt;,&lt;hash&gt;..&lt;hash&gt;
1287 mode &lt;mode&gt;,&lt;mode&gt;..&lt;mode&gt;
1288 new file mode &lt;mode&gt;
1289 deleted file mode &lt;mode&gt;,&lt;mode&gt;</tt></pre>
1290 </div></div>
1291 <div class="para"><p>The <tt>mode &lt;mode&gt;,&lt;mode&gt;..&lt;mode&gt;</tt> line appears only if at least one of
1292 the &lt;mode&gt; is different from the rest. Extended headers with
1293 information about detected contents movement (renames and
1294 copying detection) are designed to work with diff of two
1295 &lt;tree-ish&gt; and are not used by combined diff format.</p></div>
1296 </li>
1297 <li>
1299 It is followed by two-line from-file/to-file header
1300 </p>
1301 <div class="literalblock">
1302 <div class="content">
1303 <pre><tt>--- a/file
1304 +++ b/file</tt></pre>
1305 </div></div>
1306 <div class="para"><p>Similar to two-line header for traditional <em>unified</em> diff
1307 format, <tt>/dev/null</tt> is used to signal created or deleted
1308 files.</p></div>
1309 </li>
1310 <li>
1312 Chunk header format is modified to prevent people from
1313 accidentally feeding it to <tt>patch -p1</tt>. Combined diff format
1314 was created for review of merge commit changes, and was not
1315 meant for apply. The change is similar to the change in the
1316 extended <em>index</em> header:
1317 </p>
1318 <div class="literalblock">
1319 <div class="content">
1320 <pre><tt>@@@ &lt;from-file-range&gt; &lt;from-file-range&gt; &lt;to-file-range&gt; @@@</tt></pre>
1321 </div></div>
1322 <div class="para"><p>There are (number of parents + 1) <tt>@</tt> characters in the chunk
1323 header for combined diff format.</p></div>
1324 </li>
1325 </ol></div>
1326 <div class="para"><p>Unlike the traditional <em>unified</em> diff format, which shows two
1327 files A and B with a single column that has <tt>-</tt> (minus &#8212;
1328 appears in A but removed in B), <tt>+</tt> (plus &#8212; missing in A but
1329 added to B), or <tt>" "</tt> (space &#8212; unchanged) prefix, this format
1330 compares two or more files file1, file2,&#8230; with one file X, and
1331 shows how X differs from each of fileN. One column for each of
1332 fileN is prepended to the output line to note how X's line is
1333 different from it.</p></div>
1334 <div class="para"><p>A <tt>-</tt> character in the column N means that the line appears in
1335 fileN but it does not appear in the result. A <tt>+</tt> character
1336 in the column N means that the line appears in the result,
1337 and fileN does not have that line (in other words, the line was
1338 added, from the point of view of that parent).</p></div>
1339 <div class="para"><p>In the above example output, the function signature was changed
1340 from both files (hence two <tt>-</tt> removals from both file1 and
1341 file2, plus <tt>++</tt> to mean one line that was added does not appear
1342 in either file1 nor file2). Also eight other lines are the same
1343 from file1 but do not appear in file2 (hence prefixed with <tt>&#43;</tt>).</p></div>
1344 <div class="para"><p>When shown by <tt>git diff-tree -c</tt>, it compares the parents of a
1345 merge commit with the merge result (i.e. file1..fileN are the
1346 parents). When shown by <tt>git diff-files -c</tt>, it compares the
1347 two unresolved merge parents with the working tree file
1348 (i.e. file1 is stage 2 aka "our version", file2 is stage 3 aka
1349 "their version").</p></div>
1350 </div>
1351 <h2 id="_other_diff_formats">other diff formats</h2>
1352 <div class="sectionbody">
1353 <div class="para"><p>The <tt>--summary</tt> option describes newly added, deleted, renamed and
1354 copied files. The <tt>--stat</tt> option adds diffstat(1) graph to the
1355 output. These options can be combined with other options, such as
1356 <tt>-p</tt>, and are meant for human consumption.</p></div>
1357 <div class="para"><p>When showing a change that involves a rename or a copy, <tt>--stat</tt> output
1358 formats the pathnames compactly by combining common prefix and suffix of
1359 the pathnames. For example, a change that moves <tt>arch/i386/Makefile</tt> to
1360 <tt>arch/x86/Makefile</tt> while modifying 4 lines will be shown like this:</p></div>
1361 <div class="listingblock">
1362 <div class="content">
1363 <pre><tt>arch/{i386 =&gt; x86}/Makefile | 4 +--</tt></pre>
1364 </div></div>
1365 <div class="para"><p>The <tt>--numstat</tt> option gives the diffstat(1) information but is designed
1366 for easier machine consumption. An entry in <tt>--numstat</tt> output looks
1367 like this:</p></div>
1368 <div class="listingblock">
1369 <div class="content">
1370 <pre><tt>1 2 README
1371 3 1 arch/{i386 =&gt; x86}/Makefile</tt></pre>
1372 </div></div>
1373 <div class="para"><p>That is, from left to right:</p></div>
1374 <div class="olist"><ol>
1375 <li>
1377 the number of added lines;
1378 </p>
1379 </li>
1380 <li>
1382 a tab;
1383 </p>
1384 </li>
1385 <li>
1387 the number of deleted lines;
1388 </p>
1389 </li>
1390 <li>
1392 a tab;
1393 </p>
1394 </li>
1395 <li>
1397 pathname (possibly with rename/copy information);
1398 </p>
1399 </li>
1400 <li>
1402 a newline.
1403 </p>
1404 </li>
1405 </ol></div>
1406 <div class="para"><p>When <tt>-z</tt> output option is in effect, the output is formatted this way:</p></div>
1407 <div class="listingblock">
1408 <div class="content">
1409 <pre><tt>1 2 README NUL
1410 3 1 NUL arch/i386/Makefile NUL arch/x86/Makefile NUL</tt></pre>
1411 </div></div>
1412 <div class="para"><p>That is:</p></div>
1413 <div class="olist"><ol>
1414 <li>
1416 the number of added lines;
1417 </p>
1418 </li>
1419 <li>
1421 a tab;
1422 </p>
1423 </li>
1424 <li>
1426 the number of deleted lines;
1427 </p>
1428 </li>
1429 <li>
1431 a tab;
1432 </p>
1433 </li>
1434 <li>
1436 a NUL (only exists if renamed/copied);
1437 </p>
1438 </li>
1439 <li>
1441 pathname in preimage;
1442 </p>
1443 </li>
1444 <li>
1446 a NUL (only exists if renamed/copied);
1447 </p>
1448 </li>
1449 <li>
1451 pathname in postimage (only exists if renamed/copied);
1452 </p>
1453 </li>
1454 <li>
1456 a NUL.
1457 </p>
1458 </li>
1459 </ol></div>
1460 <div class="para"><p>The extra <tt>NUL</tt> before the preimage path in renamed case is to allow
1461 scripts that read the output to tell if the current record being read is
1462 a single-path record or a rename/copy record without reading ahead.
1463 After reading added and deleted lines, reading up to <tt>NUL</tt> would yield
1464 the pathname, but if that is <tt>NUL</tt>, the record will show two paths.</p></div>
1465 </div>
1466 <h2 id="_examples">EXAMPLES</h2>
1467 <div class="sectionbody">
1468 <div class="vlist"><dl>
1469 <dt>
1470 Various ways to check your working tree
1471 </dt>
1472 <dd>
1473 <div class="listingblock">
1474 <div class="content">
1475 <pre><tt>$ git diff <b>(1)</b>
1476 $ git diff --cached <b>(2)</b>
1477 $ git diff HEAD <b>(3)</b></tt></pre>
1478 </div></div>
1479 <div class="colist"><ol>
1480 <li>
1482 Changes in the working tree not yet staged for the next commit.
1483 </p>
1484 </li>
1485 <li>
1487 Changes between the index and your last commit; what you
1488 would be committing if you run "git commit" without "-a" option.
1489 </p>
1490 </li>
1491 <li>
1493 Changes in the working tree since your last commit; what you
1494 would be committing if you run "git commit -a"
1495 </p>
1496 </li>
1497 </ol></div>
1498 </dd>
1499 <dt>
1500 Comparing with arbitrary commits
1501 </dt>
1502 <dd>
1503 <div class="listingblock">
1504 <div class="content">
1505 <pre><tt>$ git diff test <b>(1)</b>
1506 $ git diff HEAD -- ./test <b>(2)</b>
1507 $ git diff HEAD^ HEAD <b>(3)</b></tt></pre>
1508 </div></div>
1509 <div class="colist"><ol>
1510 <li>
1512 Instead of using the tip of the current branch, compare with the
1513 tip of "test" branch.
1514 </p>
1515 </li>
1516 <li>
1518 Instead of comparing with the tip of "test" branch, compare with
1519 the tip of the current branch, but limit the comparison to the
1520 file "test".
1521 </p>
1522 </li>
1523 <li>
1525 Compare the version before the last commit and the last commit.
1526 </p>
1527 </li>
1528 </ol></div>
1529 </dd>
1530 <dt>
1531 Comparing branches
1532 </dt>
1533 <dd>
1534 <div class="listingblock">
1535 <div class="content">
1536 <pre><tt>$ git diff topic master <b>(1)</b>
1537 $ git diff topic..master <b>(2)</b>
1538 $ git diff topic...master <b>(3)</b></tt></pre>
1539 </div></div>
1540 <div class="colist"><ol>
1541 <li>
1543 Changes between the tips of the topic and the master branches.
1544 </p>
1545 </li>
1546 <li>
1548 Same as above.
1549 </p>
1550 </li>
1551 <li>
1553 Changes that occurred on the master branch since when the topic
1554 branch was started off it.
1555 </p>
1556 </li>
1557 </ol></div>
1558 </dd>
1559 <dt>
1560 Limiting the diff output
1561 </dt>
1562 <dd>
1563 <div class="listingblock">
1564 <div class="content">
1565 <pre><tt>$ git diff --diff-filter=MRC <b>(1)</b>
1566 $ git diff --name-status <b>(2)</b>
1567 $ git diff arch/i386 include/asm-i386 <b>(3)</b></tt></pre>
1568 </div></div>
1569 <div class="colist"><ol>
1570 <li>
1572 Show only modification, rename and copy, but not addition
1573 nor deletion.
1574 </p>
1575 </li>
1576 <li>
1578 Show only names and the nature of change, but not actual
1579 diff output.
1580 </p>
1581 </li>
1582 <li>
1584 Limit diff output to named subtrees.
1585 </p>
1586 </li>
1587 </ol></div>
1588 </dd>
1589 <dt>
1590 Munging the diff output
1591 </dt>
1592 <dd>
1593 <div class="listingblock">
1594 <div class="content">
1595 <pre><tt>$ git diff --find-copies-harder -B -C <b>(1)</b>
1596 $ git diff -R <b>(2)</b></tt></pre>
1597 </div></div>
1598 <div class="colist"><ol>
1599 <li>
1601 Spend extra cycles to find renames, copies and complete
1602 rewrites (very expensive).
1603 </p>
1604 </li>
1605 <li>
1607 Output diff in reverse.
1608 </p>
1609 </li>
1610 </ol></div>
1611 </dd>
1612 </dl></div>
1613 </div>
1614 <h2 id="_see_also">SEE ALSO</h2>
1615 <div class="sectionbody">
1616 <div class="vlist"><dl>
1617 <dt>
1618 <a href="git-difftool.html">git-difftool(1)</a>
1619 </dt>
1620 <dd>
1622 Show changes using common diff tools
1623 </p>
1624 </dd>
1625 </dl></div>
1626 </div>
1627 <h2 id="_author">Author</h2>
1628 <div class="sectionbody">
1629 <div class="para"><p>Written by Linus Torvalds &lt;torvalds@osdl.org&gt;</p></div>
1630 </div>
1631 <h2 id="_documentation">Documentation</h2>
1632 <div class="sectionbody">
1633 <div class="para"><p>Documentation by Junio C Hamano and the git-list &lt;git@vger.kernel.org&gt;.</p></div>
1634 </div>
1635 <h2 id="_git">GIT</h2>
1636 <div class="sectionbody">
1637 <div class="para"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
1638 </div>
1639 <div id="footer">
1640 <div id="footer-text">
1641 Last updated 2010-03-25 00:38:22 UTC
1642 </div>
1643 </div>
1644 </body>
1645 </html>