blob: 0ac711230e24bf7238b2e3a215cdc3c4ce0d2087 [file] [log] [blame]
Junio C Hamano215a7ad2005-09-07 17:26:23 -07001git-diff(1)
2===========
Junio C Hamano7fc9d692005-08-23 01:49:47 -07003
4NAME
5----
Fredrik Kuivinen7bd7f282006-03-09 17:24:50 +01006git-diff - Show changes between commits, commit and working tree, etc
Junio C Hamano7fc9d692005-08-23 01:49:47 -07007
8
9SYNOPSIS
10--------
Jonathan Niederb1889c32008-06-30 01:09:04 -050011'git diff' [<common diff options>] <commit>{0,2} [--] [<path>...]
Junio C Hamano7fc9d692005-08-23 01:49:47 -070012
13DESCRIPTION
14-----------
Matthias Lederhofercfc01c02006-07-09 11:59:39 +020015Show changes between two trees, a tree and the working tree, a
16tree and the index file, or the index file and the working tree.
Junio C Hamano7fc9d692005-08-23 01:49:47 -070017
Jonathan Niederb1889c32008-06-30 01:09:04 -050018'git diff' [--options] [--] [<path>...]::
Junio C Hamanodfa2f222005-12-05 00:22:01 -080019
Junio C Hamanof5e6b892006-12-14 00:03:18 -080020 This form is to view the changes you made relative to
21 the index (staging area for the next commit). In other
22 words, the differences are what you _could_ tell git to
23 further add to the index but you still haven't. You can
Dan McGee5162e692007-12-29 00:20:38 -060024 stage these changes by using linkgit:git-add[1].
Mike Hommey2b9232c2007-08-27 22:05:19 -070025+
26If exactly two paths are given, and at least one is untracked,
27compare the two files / directories. This behavior can be
28forced by --no-index.
Johannes Schindelind516c2d2007-02-22 21:50:10 +010029
Jonathan Niederb1889c32008-06-30 01:09:04 -050030'git diff' [--options] --cached [<commit>] [--] [<path>...]::
Junio C Hamanof5e6b892006-12-14 00:03:18 -080031
32 This form is to view the changes you staged for the next
Junio C Hamanoce054542006-12-20 14:41:54 -080033 commit relative to the named <commit>. Typically you
Junio C Hamanof5e6b892006-12-14 00:03:18 -080034 would want comparison with the latest commit, so if you
35 do not give <commit>, it defaults to HEAD.
David Symonds2baf1852008-10-29 09:15:36 -070036 --staged is a synonym of --cached.
Junio C Hamanof5e6b892006-12-14 00:03:18 -080037
Jonathan Niederb1889c32008-06-30 01:09:04 -050038'git diff' [--options] <commit> [--] [<path>...]::
Junio C Hamanof5e6b892006-12-14 00:03:18 -080039
40 This form is to view the changes you have in your
41 working tree relative to the named <commit>. You can
42 use HEAD to compare it with the latest commit, or a
43 branch name to compare with the tip of a different
44 branch.
45
Jonathan Niederb1889c32008-06-30 01:09:04 -050046'git diff' [--options] <commit> <commit> [--] [<path>...]::
Junio C Hamanof5e6b892006-12-14 00:03:18 -080047
Mike Hommey2b9232c2007-08-27 22:05:19 -070048 This is to view the changes between two arbitrary
49 <commit>.
50
Jonathan Niederb1889c32008-06-30 01:09:04 -050051'git diff' [--options] <commit>..<commit> [--] [<path>...]::
Mike Hommey2b9232c2007-08-27 22:05:19 -070052
53 This is synonymous to the previous form. If <commit> on
54 one side is omitted, it will have the same effect as
55 using HEAD instead.
56
Jonathan Niederb1889c32008-06-30 01:09:04 -050057'git diff' [--options] <commit>\...<commit> [--] [<path>...]::
Mike Hommey2b9232c2007-08-27 22:05:19 -070058
59 This form is to view the changes on the branch containing
60 and up to the second <commit>, starting at a common ancestor
Jonathan Niederb1889c32008-06-30 01:09:04 -050061 of both <commit>. "git diff A\...B" is equivalent to
62 "git diff $(git-merge-base A B) B". You can omit any one
Mike Hommey2b9232c2007-08-27 22:05:19 -070063 of <commit>, which has the same effect as using HEAD instead.
Junio C Hamanof5e6b892006-12-14 00:03:18 -080064
65Just in case if you are doing something exotic, it should be
Junio C Hamano0c783f62007-08-28 21:47:08 -070066noted that all of the <commit> in the above description, except
67for the last two forms that use ".." notations, can be any
68<tree-ish>.
Junio C Hamanof5e6b892006-12-14 00:03:18 -080069
Shawn O. Pearce41a55642007-01-17 21:08:09 -050070For a more complete list of ways to spell <commit>, see
Dan McGee5162e692007-12-29 00:20:38 -060071"SPECIFYING REVISIONS" section in linkgit:git-rev-parse[1].
Mike Hommey2b9232c2007-08-27 22:05:19 -070072However, "diff" is about comparing two _endpoints_, not ranges,
73and the range notations ("<commit>..<commit>" and
Junio C Hamano0c783f62007-08-28 21:47:08 -070074"<commit>\...<commit>") do not mean a range as defined in the
Dan McGee5162e692007-12-29 00:20:38 -060075"SPECIFYING RANGES" section in linkgit:git-rev-parse[1].
Junio C Hamano7fc9d692005-08-23 01:49:47 -070076
77OPTIONS
78-------
Sergei Organovc1a95fa2007-11-15 16:19:29 +030079:git-diff: 1
Junio C Hamanof5e6b892006-12-14 00:03:18 -080080include::diff-options.txt[]
Junio C Hamano7fc9d692005-08-23 01:49:47 -070081
Junio C Hamano35ef3a42005-09-07 23:04:52 -070082<path>...::
Junio C Hamanof5e6b892006-12-14 00:03:18 -080083 The <paths> parameters, when given, are used to limit
84 the diff to the named paths (you can give directory
85 names and get diff for all files under them).
Junio C Hamano7fc9d692005-08-23 01:49:47 -070086
David Kågedalf552e512009-07-28 10:32:18 +020087
Gerrit Pape9e6c7232007-10-31 13:59:16 +000088include::diff-format.txt[]
Junio C Hamano7fc9d692005-08-23 01:49:47 -070089
Junio C Hamano803f4982005-12-13 01:54:15 -080090EXAMPLES
91--------
92
93Various ways to check your working tree::
94+
95------------
Sean Estabrooks48aeecd2006-04-28 09:15:05 -040096$ git diff <1>
Junio C Hamanof2dd1c92006-12-13 01:33:43 -080097$ git diff --cached <2>
Sean Estabrooks48aeecd2006-04-28 09:15:05 -040098$ git diff HEAD <3>
99------------
100+
Steve Hoelzer434e6ef2007-08-01 10:43:06 -0500101<1> Changes in the working tree not yet staged for the next commit.
102<2> Changes between the index and your last commit; what you
Junio C Hamano803f4982005-12-13 01:54:15 -0800103would be committing if you run "git commit" without "-a" option.
Steve Hoelzer434e6ef2007-08-01 10:43:06 -0500104<3> Changes in the working tree since your last commit; what you
Junio C Hamano803f4982005-12-13 01:54:15 -0800105would be committing if you run "git commit -a"
Junio C Hamano803f4982005-12-13 01:54:15 -0800106
107Comparing with arbitrary commits::
108+
109------------
Sean Estabrooks48aeecd2006-04-28 09:15:05 -0400110$ git diff test <1>
111$ git diff HEAD -- ./test <2>
112$ git diff HEAD^ HEAD <3>
113------------
114+
Steve Hoelzer434e6ef2007-08-01 10:43:06 -0500115<1> Instead of using the tip of the current branch, compare with the
Junio C Hamano803f4982005-12-13 01:54:15 -0800116tip of "test" branch.
Steve Hoelzer434e6ef2007-08-01 10:43:06 -0500117<2> Instead of comparing with the tip of "test" branch, compare with
Junio C Hamano89438672005-12-29 01:20:06 -0800118the tip of the current branch, but limit the comparison to the
Junio C Hamano803f4982005-12-13 01:54:15 -0800119file "test".
Steve Hoelzer434e6ef2007-08-01 10:43:06 -0500120<3> Compare the version before the last commit and the last commit.
Junio C Hamano803f4982005-12-13 01:54:15 -0800121
Mike Hommey2b9232c2007-08-27 22:05:19 -0700122Comparing branches::
123+
124------------
125$ git diff topic master <1>
126$ git diff topic..master <2>
127$ git diff topic...master <3>
128------------
129+
130<1> Changes between the tips of the topic and the master branches.
131<2> Same as above.
Ralf Wildenhues06ada152007-10-09 23:00:03 +0200132<3> Changes that occurred on the master branch since when the topic
Mike Hommey2b9232c2007-08-27 22:05:19 -0700133branch was started off it.
Junio C Hamano803f4982005-12-13 01:54:15 -0800134
135Limiting the diff output::
136+
137------------
Sean Estabrooks48aeecd2006-04-28 09:15:05 -0400138$ git diff --diff-filter=MRC <1>
Jeff King90ae7102007-07-28 20:24:27 -0400139$ git diff --name-status <2>
Sean Estabrooks48aeecd2006-04-28 09:15:05 -0400140$ git diff arch/i386 include/asm-i386 <3>
141------------
142+
Steve Hoelzer434e6ef2007-08-01 10:43:06 -0500143<1> Show only modification, rename and copy, but not addition
Junio C Hamano803f4982005-12-13 01:54:15 -0800144nor deletion.
Steve Hoelzer434e6ef2007-08-01 10:43:06 -0500145<2> Show only names and the nature of change, but not actual
Jeff King90ae7102007-07-28 20:24:27 -0400146diff output.
Steve Hoelzer434e6ef2007-08-01 10:43:06 -0500147<3> Limit diff output to named subtrees.
Junio C Hamano803f4982005-12-13 01:54:15 -0800148
149Munging the diff output::
150+
151------------
Sean Estabrooks48aeecd2006-04-28 09:15:05 -0400152$ git diff --find-copies-harder -B -C <1>
153$ git diff -R <2>
154------------
155+
Steve Hoelzer434e6ef2007-08-01 10:43:06 -0500156<1> Spend extra cycles to find renames, copies and complete
Junio C Hamano803f4982005-12-13 01:54:15 -0800157rewrites (very expensive).
Steve Hoelzer434e6ef2007-08-01 10:43:06 -0500158<2> Output diff in reverse.
Junio C Hamano803f4982005-12-13 01:54:15 -0800159
160
Junio C Hamano7fc9d692005-08-23 01:49:47 -0700161Author
162------
163Written by Linus Torvalds <torvalds@osdl.org>
164
165Documentation
166--------------
167Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
168
169GIT
170---
Christian Couder9e1f0a82008-06-06 09:07:32 +0200171Part of the linkgit:git[1] suite