blob: b180f1fa5bf5599efd8c8fefe29e3249cd387715 [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 Hamano2e6ded82010-12-05 06:20:4811[verse]
Junio C Hamanoc9cb5172018-06-01 07:13:4412'git diff' [<options>] [<commit>] [--] [<path>...]
13'git diff' [<options>] --cached [<commit>] [--] [<path>...]
14'git diff' [<options>] <commit> <commit> [--] [<path>...]
15'git diff' [<options>] <blob> <blob>
16'git diff' [<options>] --no-index [--] <path> <path>
Junio C Hamano1a4e8412005-12-27 08:17:2317
18DESCRIPTION
19-----------
Junio C Hamano2e6ded82010-12-05 06:20:4820Show changes between the working tree and the index or a tree, changes
Junio C Hamano3a3357e2013-06-26 23:20:5621between the index and a tree, changes between two trees, changes between
22two blob objects, or changes between two files on disk.
Junio C Hamano1a4e8412005-12-27 08:17:2323
Junio C Hamanoc9cb5172018-06-01 07:13:4424'git diff' [<options>] [--] [<path>...]::
Junio C Hamano1a4e8412005-12-27 08:17:2325
Junio C Hamano47848ae2006-12-14 11:20:0626This form is to view the changes you made relative to
27the index (staging area for the next commit). In other
Junio C Hamano076ffcc2013-02-06 05:13:2128words, the differences are what you _could_ tell Git to
Junio C Hamano47848ae2006-12-14 11:20:0629further add to the index but you still haven't. You can
Junio C Hamano35738e82008-01-07 07:55:4630stage these changes by using linkgit:git-add[1].
Junio C Hamanoe6f28d02013-09-17 21:34:0031
Junio C Hamanoc9cb5172018-06-01 07:13:4432'git diff' [<options>] --no-index [--] <path> <path>::
Junio C Hamanoe6f28d02013-09-17 21:34:0033
34This form is to compare the given two paths on the
35filesystem. You can omit the `--no-index` option when
36running the command in a working tree controlled by Git and
37at least one of the paths points outside the working tree,
38or when running the command outside a working tree
39controlled by Git.
Junio C Hamanodb911ee2007-02-28 08:13:5240
Junio C Hamanoc9cb5172018-06-01 07:13:4441'git diff' [<options>] --cached [<commit>] [--] [<path>...]::
Junio C Hamano47848ae2006-12-14 11:20:0642
43This form is to view the changes you staged for the next
Junio C Hamano4bf6dca2006-12-21 02:25:5744commit relative to the named <commit>. Typically you
Junio C Hamano47848ae2006-12-14 11:20:0645would want comparison with the latest commit, so if you
46do not give <commit>, it defaults to HEAD.
Junio C Hamano826f5c42014-02-07 20:33:3047If HEAD does not exist (e.g. unborn branches) and
Junio C Hamanoe6116832011-02-08 00:49:4548<commit> is not given, it shows all staged changes.
Junio C Hamano8b4977b2008-11-12 04:57:4849--staged is a synonym of --cached.
Junio C Hamano47848ae2006-12-14 11:20:0650
Junio C Hamanoc9cb5172018-06-01 07:13:4451'git diff' [<options>] <commit> [--] [<path>...]::
Junio C Hamano47848ae2006-12-14 11:20:0652
53This form is to view the changes you have in your
54working tree relative to the named <commit>. You can
55use HEAD to compare it with the latest commit, or a
56branch name to compare with the tip of a different
57branch.
58
Junio C Hamanoc9cb5172018-06-01 07:13:4459'git diff' [<options>] <commit> <commit> [--] [<path>...]::
Junio C Hamano47848ae2006-12-14 11:20:0660
Junio C Hamanoc435b1c2007-08-28 06:25:3561This is to view the changes between two arbitrary
62<commit>.
63
Junio C Hamanoc9cb5172018-06-01 07:13:4464'git diff' [<options>] <commit>..<commit> [--] [<path>...]::
Junio C Hamanoc435b1c2007-08-28 06:25:3565
66This is synonymous to the previous form. If <commit> on
67one side is omitted, it will have the same effect as
68using HEAD instead.
69
Junio C Hamanoc9cb5172018-06-01 07:13:4470'git diff' [<options>] <commit>\...<commit> [--] [<path>...]::
Junio C Hamanoc435b1c2007-08-28 06:25:3571
72This form is to view the changes on the branch containing
73and up to the second <commit>, starting at a common ancestor
Junio C Hamanofce7c7e2008-07-02 03:06:3874of both <commit>. "git diff A\...B" is equivalent to
75"git diff $(git-merge-base A B) B". You can omit any one
Junio C Hamanoc435b1c2007-08-28 06:25:3576of <commit>, which has the same effect as using HEAD instead.
Junio C Hamano47848ae2006-12-14 11:20:0677
78Just in case if you are doing something exotic, it should be
Junio C Hamano7d9e9bd2007-08-29 07:31:4779noted that all of the <commit> in the above description, except
Junio C Hamanoc27b7332010-10-14 04:37:2880in the last two forms that use ".." notations, can be any
Junio C Hamanodb81b992012-12-21 23:49:1281<tree>.
Junio C Hamano47848ae2006-12-14 11:20:0682
Junio C Hamano2d47c622007-01-18 06:24:1083For a more complete list of ways to spell <commit>, see
Junio C Hamanoc27b7332010-10-14 04:37:2884"SPECIFYING REVISIONS" section in linkgit:gitrevisions[7].
Junio C Hamanoc435b1c2007-08-28 06:25:3585However, "diff" is about comparing two _endpoints_, not ranges,
86and the range notations ("<commit>..<commit>" and
Junio C Hamano7d9e9bd2007-08-29 07:31:4787"<commit>\...<commit>") do not mean a range as defined in the
Junio C Hamanoc27b7332010-10-14 04:37:2888"SPECIFYING RANGES" section in linkgit:gitrevisions[7].
Junio C Hamano1a4e8412005-12-27 08:17:2389
Junio C Hamanoc9cb5172018-06-01 07:13:4490'git diff' [<options>] <blob> <blob>::
Junio C Hamano3a3357e2013-06-26 23:20:5691
92This form is to view the differences between the raw
93contents of two blob objects.
94
Junio C Hamano1a4e8412005-12-27 08:17:2395OPTIONS
96-------
Junio C Hamanoff979792007-11-16 10:11:3097:git-diff: 1
Junio C Hamano47848ae2006-12-14 11:20:0698include::diff-options.txt[]
Junio C Hamano1a4e8412005-12-27 08:17:2399
Junio C Hamano52a094d2017-04-20 05:35:10100-1 --base::
101-2 --ours::
102-3 --theirs::
103Compare the working tree with the "base" version (stage #1),
104"our branch" (stage #2) or "their branch" (stage #3). The
105index contains these stages only for unmerged entries i.e.
106while resolving conflicts. See linkgit:git-read-tree[1]
107section "3-Way Merge" for detailed information.
108
109-0::
110Omit diff output for unmerged entries and just show
111"Unmerged". Can be used only when comparing the working tree
112with the index.
113
Junio C Hamano1a4e8412005-12-27 08:17:23114<path>...::
Junio C Hamano47848ae2006-12-14 11:20:06115The <paths> parameters, when given, are used to limit
116the diff to the named paths (you can give directory
117names and get diff for all files under them).
Junio C Hamano1a4e8412005-12-27 08:17:23118
Junio C Hamano543f8d62009-07-29 08:35:21119
Junio C Hamano7ae0ab22007-11-03 02:46:46120include::diff-format.txt[]
Junio C Hamano1a4e8412005-12-27 08:17:23121
122EXAMPLES
123--------
124
125Various ways to check your working tree::
126+
127------------
Junio C Hamanoc8d88c22006-04-29 07:02:01128$ git diff <1>
Junio C Hamano47848ae2006-12-14 11:20:06129$ git diff --cached <2>
Junio C Hamanoc8d88c22006-04-29 07:02:01130$ git diff HEAD <3>
131------------
132+
Junio C Hamano092f5f02007-08-02 07:23:38133<1> Changes in the working tree not yet staged for the next commit.
134<2> Changes between the index and your last commit; what you
Junio C Hamano1a4e8412005-12-27 08:17:23135would be committing if you run "git commit" without "-a" option.
Junio C Hamano092f5f02007-08-02 07:23:38136<3> Changes in the working tree since your last commit; what you
Junio C Hamano1a4e8412005-12-27 08:17:23137would be committing if you run "git commit -a"
Junio C Hamano1a4e8412005-12-27 08:17:23138
139Comparing with arbitrary commits::
140+
141------------
Junio C Hamanoc8d88c22006-04-29 07:02:01142$ git diff test <1>
143$ git diff HEAD -- ./test <2>
144$ git diff HEAD^ HEAD <3>
145------------
146+
Junio C Hamano092f5f02007-08-02 07:23:38147<1> Instead of using the tip of the current branch, compare with the
Junio C Hamano1a4e8412005-12-27 08:17:23148tip of "test" branch.
Junio C Hamano092f5f02007-08-02 07:23:38149<2> Instead of comparing with the tip of "test" branch, compare with
Junio C Hamano235a91e2006-01-07 01:13:58150the tip of the current branch, but limit the comparison to the
Junio C Hamano1a4e8412005-12-27 08:17:23151file "test".
Junio C Hamano092f5f02007-08-02 07:23:38152<3> Compare the version before the last commit and the last commit.
Junio C Hamano1a4e8412005-12-27 08:17:23153
Junio C Hamanoc435b1c2007-08-28 06:25:35154Comparing branches::
155+
156------------
157$ git diff topic master <1>
158$ git diff topic..master <2>
159$ git diff topic...master <3>
160------------
161+
162<1> Changes between the tips of the topic and the master branches.
163<2> Same as above.
Junio C Hamano764a6672007-10-23 01:23:31164<3> Changes that occurred on the master branch since when the topic
Junio C Hamanoc435b1c2007-08-28 06:25:35165branch was started off it.
Junio C Hamano1a4e8412005-12-27 08:17:23166
167Limiting the diff output::
168+
169------------
Junio C Hamanoc8d88c22006-04-29 07:02:01170$ git diff --diff-filter=MRC <1>
Junio C Hamanobdeff822007-07-30 09:07:17171$ git diff --name-status <2>
Junio C Hamanoc8d88c22006-04-29 07:02:01172$ git diff arch/i386 include/asm-i386 <3>
173------------
174+
Junio C Hamanod75148a2014-04-08 19:48:38175<1> Show only modification, rename, and copy, but not addition
176or deletion.
Junio C Hamano092f5f02007-08-02 07:23:38177<2> Show only names and the nature of change, but not actual
Junio C Hamanobdeff822007-07-30 09:07:17178diff output.
Junio C Hamano092f5f02007-08-02 07:23:38179<3> Limit diff output to named subtrees.
Junio C Hamano1a4e8412005-12-27 08:17:23180
181Munging the diff output::
182+
183------------
Junio C Hamanoc8d88c22006-04-29 07:02:01184$ git diff --find-copies-harder -B -C <1>
185$ git diff -R <2>
186------------
187+
Junio C Hamano092f5f02007-08-02 07:23:38188<1> Spend extra cycles to find renames, copies and complete
Junio C Hamano1a4e8412005-12-27 08:17:23189rewrites (very expensive).
Junio C Hamano092f5f02007-08-02 07:23:38190<2> Output diff in reverse.
Junio C Hamano1a4e8412005-12-27 08:17:23191
Junio C Hamanoa9701f02010-01-21 00:42:16192SEE ALSO
193--------
Junio C Hamanoc27b7332010-10-14 04:37:28194diff(1),
195linkgit:git-difftool[1],
196linkgit:git-log[1],
197linkgit:gitdiffcore[7],
198linkgit:git-format-patch[1],
199linkgit:git-apply[1]
Junio C Hamano1a4e8412005-12-27 08:17:23200
Junio C Hamano1a4e8412005-12-27 08:17:23201GIT
202---
Junio C Hamanof7c042d2008-06-06 22:50:53203Part of the linkgit:git[1] suite