blob: db2eb46a191ecafac09492b95ec6f3a3233dbc6e [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231git-diff(1)
2===========
3
4NAME
5----
Junio C Hamano01078922006-03-10 00:31:476git-diff - Show changes between commits, commit and working tree, etc
Junio C Hamano1a4e8412005-12-27 08:17:237
8
9SYNOPSIS
10--------
Junio C Hamano60f8aa82007-03-06 09:58:2611'git-diff' [<common diff options>] <commit>{0,2} [--] [<path>...]
Junio C Hamano1a4e8412005-12-27 08:17:2312
13DESCRIPTION
14-----------
Junio C Hamano51c2ab02006-07-09 20:38:5415Show 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 Hamano1a4e8412005-12-27 08:17:2317
Junio C Hamano47848ae2006-12-14 11:20:0618'git-diff' [--options] [--] [<path>...]::
Junio C Hamano1a4e8412005-12-27 08:17:2319
Junio C Hamano47848ae2006-12-14 11:20:0620This form is to view the changes you made relative to
21the index (staging area for the next commit). In other
22words, the differences are what you _could_ tell git to
23further add to the index but you still haven't. You can
24stage these changes by using gitlink:git-add[1].
Junio C Hamanoc435b1c2007-08-28 06:25:3525+
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.
Junio C Hamanodb911ee2007-02-28 08:13:5229
Junio C Hamano47848ae2006-12-14 11:20:0630'git-diff' [--options] --cached [<commit>] [--] [<path>...]::
31
32This form is to view the changes you staged for the next
Junio C Hamano4bf6dca2006-12-21 02:25:5733commit relative to the named <commit>. Typically you
Junio C Hamano47848ae2006-12-14 11:20:0634would want comparison with the latest commit, so if you
35do not give <commit>, it defaults to HEAD.
36
Junio C Hamano7d23f5e2006-12-16 07:44:0437'git-diff' [--options] <commit> [--] [<path>...]::
Junio C Hamano47848ae2006-12-14 11:20:0638
39This form is to view the changes you have in your
40working tree relative to the named <commit>. You can
41use HEAD to compare it with the latest commit, or a
42branch name to compare with the tip of a different
43branch.
44
Junio C Hamano7d23f5e2006-12-16 07:44:0445'git-diff' [--options] <commit> <commit> [--] [<path>...]::
Junio C Hamano47848ae2006-12-14 11:20:0646
Junio C Hamanoc435b1c2007-08-28 06:25:3547This is to view the changes between two arbitrary
48<commit>.
49
50'git-diff' [--options] <commit>..<commit> [--] [<path>...]::
51
52This is synonymous to the previous form. If <commit> on
53one side is omitted, it will have the same effect as
54using HEAD instead.
55
Junio C Hamano7d9e9bd2007-08-29 07:31:4756'git-diff' [--options] <commit>\...<commit> [--] [<path>...]::
Junio C Hamanoc435b1c2007-08-28 06:25:3557
58This form is to view the changes on the branch containing
59and up to the second <commit>, starting at a common ancestor
Junio C Hamano7d9e9bd2007-08-29 07:31:4760of both <commit>. "git-diff A\...B" is equivalent to
Junio C Hamanoc435b1c2007-08-28 06:25:3561"git-diff $(git-merge-base A B) B". You can omit any one
62of <commit>, which has the same effect as using HEAD instead.
Junio C Hamano47848ae2006-12-14 11:20:0663
64Just in case if you are doing something exotic, it should be
Junio C Hamano7d9e9bd2007-08-29 07:31:4765noted that all of the <commit> in the above description, except
66for the last two forms that use ".." notations, can be any
67<tree-ish>.
Junio C Hamano47848ae2006-12-14 11:20:0668
Junio C Hamano2d47c622007-01-18 06:24:1069For a more complete list of ways to spell <commit>, see
70"SPECIFYING REVISIONS" section in gitlink:git-rev-parse[1].
Junio C Hamanoc435b1c2007-08-28 06:25:3571However, "diff" is about comparing two _endpoints_, not ranges,
72and the range notations ("<commit>..<commit>" and
Junio C Hamano7d9e9bd2007-08-29 07:31:4773"<commit>\...<commit>") do not mean a range as defined in the
Junio C Hamanoc435b1c2007-08-28 06:25:3574"SPECIFYING RANGES" section in gitlink:git-rev-parse[1].
Junio C Hamano1a4e8412005-12-27 08:17:2375
76OPTIONS
77-------
Junio C Hamano47848ae2006-12-14 11:20:0678include::diff-options.txt[]
Junio C Hamano1a4e8412005-12-27 08:17:2379
80<path>...::
Junio C Hamano47848ae2006-12-14 11:20:0681The <paths> parameters, when given, are used to limit
82the diff to the named paths (you can give directory
83names and get diff for all files under them).
Junio C Hamano1a4e8412005-12-27 08:17:2384
85
86EXAMPLES
87--------
88
89Various ways to check your working tree::
90+
91------------
Junio C Hamanoc8d88c22006-04-29 07:02:0192$ git diff <1>
Junio C Hamano47848ae2006-12-14 11:20:0693$ git diff --cached <2>
Junio C Hamanoc8d88c22006-04-29 07:02:0194$ git diff HEAD <3>
95------------
96+
Junio C Hamano092f5f02007-08-02 07:23:3897<1> Changes in the working tree not yet staged for the next commit.
98<2> Changes between the index and your last commit; what you
Junio C Hamano1a4e8412005-12-27 08:17:2399would be committing if you run "git commit" without "-a" option.
Junio C Hamano092f5f02007-08-02 07:23:38100<3> Changes in the working tree since your last commit; what you
Junio C Hamano1a4e8412005-12-27 08:17:23101would be committing if you run "git commit -a"
Junio C Hamano1a4e8412005-12-27 08:17:23102
103Comparing with arbitrary commits::
104+
105------------
Junio C Hamanoc8d88c22006-04-29 07:02:01106$ git diff test <1>
107$ git diff HEAD -- ./test <2>
108$ git diff HEAD^ HEAD <3>
109------------
110+
Junio C Hamano092f5f02007-08-02 07:23:38111<1> Instead of using the tip of the current branch, compare with the
Junio C Hamano1a4e8412005-12-27 08:17:23112tip of "test" branch.
Junio C Hamano092f5f02007-08-02 07:23:38113<2> Instead of comparing with the tip of "test" branch, compare with
Junio C Hamano235a91e2006-01-07 01:13:58114the tip of the current branch, but limit the comparison to the
Junio C Hamano1a4e8412005-12-27 08:17:23115file "test".
Junio C Hamano092f5f02007-08-02 07:23:38116<3> Compare the version before the last commit and the last commit.
Junio C Hamano1a4e8412005-12-27 08:17:23117
Junio C Hamanoc435b1c2007-08-28 06:25:35118Comparing branches::
119+
120------------
121$ git diff topic master <1>
122$ git diff topic..master <2>
123$ git diff topic...master <3>
124------------
125+
126<1> Changes between the tips of the topic and the master branches.
127<2> Same as above.
128<3> Changes that occured on the master branch since when the topic
129branch was started off it.
Junio C Hamano1a4e8412005-12-27 08:17:23130
131Limiting the diff output::
132+
133------------
Junio C Hamanoc8d88c22006-04-29 07:02:01134$ git diff --diff-filter=MRC <1>
Junio C Hamanobdeff822007-07-30 09:07:17135$ git diff --name-status <2>
Junio C Hamanoc8d88c22006-04-29 07:02:01136$ git diff arch/i386 include/asm-i386 <3>
137------------
138+
Junio C Hamano092f5f02007-08-02 07:23:38139<1> Show only modification, rename and copy, but not addition
Junio C Hamano1a4e8412005-12-27 08:17:23140nor deletion.
Junio C Hamano092f5f02007-08-02 07:23:38141<2> Show only names and the nature of change, but not actual
Junio C Hamanobdeff822007-07-30 09:07:17142diff output.
Junio C Hamano092f5f02007-08-02 07:23:38143<3> Limit diff output to named subtrees.
Junio C Hamano1a4e8412005-12-27 08:17:23144
145Munging the diff output::
146+
147------------
Junio C Hamanoc8d88c22006-04-29 07:02:01148$ git diff --find-copies-harder -B -C <1>
149$ git diff -R <2>
150------------
151+
Junio C Hamano092f5f02007-08-02 07:23:38152<1> Spend extra cycles to find renames, copies and complete
Junio C Hamano1a4e8412005-12-27 08:17:23153rewrites (very expensive).
Junio C Hamano092f5f02007-08-02 07:23:38154<2> Output diff in reverse.
Junio C Hamano1a4e8412005-12-27 08:17:23155
156
157Author
158------
159Written by Linus Torvalds <torvalds@osdl.org>
160
161Documentation
162--------------
163Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
164
165GIT
166---
167Part of the gitlink:git[7] suite