2005-09-08 08:26:23 +08:00
|
|
|
git-diff(1)
|
|
|
|
===========
|
2005-08-23 16:49:47 +08:00
|
|
|
|
|
|
|
NAME
|
|
|
|
----
|
2006-03-10 00:24:50 +08:00
|
|
|
git-diff - Show changes between commits, commit and working tree, etc
|
2005-08-23 16:49:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
--------
|
2008-06-30 14:09:04 +08:00
|
|
|
'git diff' [<common diff options>] <commit>{0,2} [--] [<path>...]
|
2005-08-23 16:49:47 +08:00
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
-----------
|
2006-07-09 17:59:39 +08:00
|
|
|
Show changes between two trees, a tree and the working tree, a
|
|
|
|
tree and the index file, or the index file and the working tree.
|
2005-09-08 14:04:52 +08:00
|
|
|
|
2008-06-30 14:09:04 +08:00
|
|
|
'git diff' [--options] [--] [<path>...]::
|
2005-12-05 16:22:01 +08:00
|
|
|
|
2006-12-14 16:03:18 +08:00
|
|
|
This form is to view the changes you made relative to
|
|
|
|
the index (staging area for the next commit). In other
|
|
|
|
words, the differences are what you _could_ tell git to
|
|
|
|
further add to the index but you still haven't. You can
|
2007-12-29 14:20:38 +08:00
|
|
|
stage these changes by using linkgit:git-add[1].
|
2007-08-28 13:05:19 +08:00
|
|
|
+
|
|
|
|
If exactly two paths are given, and at least one is untracked,
|
|
|
|
compare the two files / directories. This behavior can be
|
|
|
|
forced by --no-index.
|
2007-02-23 04:50:10 +08:00
|
|
|
|
2008-06-30 14:09:04 +08:00
|
|
|
'git diff' [--options] --cached [<commit>] [--] [<path>...]::
|
2006-12-14 16:03:18 +08:00
|
|
|
|
|
|
|
This form is to view the changes you staged for the next
|
2006-12-21 06:41:54 +08:00
|
|
|
commit relative to the named <commit>. Typically you
|
2006-12-14 16:03:18 +08:00
|
|
|
would want comparison with the latest commit, so if you
|
|
|
|
do not give <commit>, it defaults to HEAD.
|
2008-10-30 00:15:36 +08:00
|
|
|
--staged is a synonym of --cached.
|
2006-12-14 16:03:18 +08:00
|
|
|
|
2008-06-30 14:09:04 +08:00
|
|
|
'git diff' [--options] <commit> [--] [<path>...]::
|
2006-12-14 16:03:18 +08:00
|
|
|
|
|
|
|
This form is to view the changes you have in your
|
|
|
|
working tree relative to the named <commit>. You can
|
|
|
|
use HEAD to compare it with the latest commit, or a
|
|
|
|
branch name to compare with the tip of a different
|
|
|
|
branch.
|
|
|
|
|
2008-06-30 14:09:04 +08:00
|
|
|
'git diff' [--options] <commit> <commit> [--] [<path>...]::
|
2006-12-14 16:03:18 +08:00
|
|
|
|
2007-08-28 13:05:19 +08:00
|
|
|
This is to view the changes between two arbitrary
|
|
|
|
<commit>.
|
|
|
|
|
2008-06-30 14:09:04 +08:00
|
|
|
'git diff' [--options] <commit>..<commit> [--] [<path>...]::
|
2007-08-28 13:05:19 +08:00
|
|
|
|
|
|
|
This is synonymous to the previous form. If <commit> on
|
|
|
|
one side is omitted, it will have the same effect as
|
|
|
|
using HEAD instead.
|
|
|
|
|
2008-06-30 14:09:04 +08:00
|
|
|
'git diff' [--options] <commit>\...<commit> [--] [<path>...]::
|
2007-08-28 13:05:19 +08:00
|
|
|
|
|
|
|
This form is to view the changes on the branch containing
|
|
|
|
and up to the second <commit>, starting at a common ancestor
|
2008-06-30 14:09:04 +08:00
|
|
|
of both <commit>. "git diff A\...B" is equivalent to
|
|
|
|
"git diff $(git-merge-base A B) B". You can omit any one
|
2007-08-28 13:05:19 +08:00
|
|
|
of <commit>, which has the same effect as using HEAD instead.
|
2006-12-14 16:03:18 +08:00
|
|
|
|
|
|
|
Just in case if you are doing something exotic, it should be
|
2007-08-29 12:47:08 +08:00
|
|
|
noted that all of the <commit> in the above description, except
|
|
|
|
for the last two forms that use ".." notations, can be any
|
|
|
|
<tree-ish>.
|
2005-12-05 16:22:01 +08:00
|
|
|
|
2007-01-18 10:08:09 +08:00
|
|
|
For a more complete list of ways to spell <commit>, see
|
2010-07-06 00:11:41 +08:00
|
|
|
"SPECIFYING REVISIONS" section in linkgit:gitrevisions[1].
|
2007-08-28 13:05:19 +08:00
|
|
|
However, "diff" is about comparing two _endpoints_, not ranges,
|
|
|
|
and the range notations ("<commit>..<commit>" and
|
2007-08-29 12:47:08 +08:00
|
|
|
"<commit>\...<commit>") do not mean a range as defined in the
|
2010-07-06 00:11:41 +08:00
|
|
|
"SPECIFYING RANGES" section in linkgit:gitrevisions[1].
|
2005-08-23 16:49:47 +08:00
|
|
|
|
|
|
|
OPTIONS
|
|
|
|
-------
|
2007-11-15 21:19:29 +08:00
|
|
|
:git-diff: 1
|
2006-12-14 16:03:18 +08:00
|
|
|
include::diff-options.txt[]
|
2005-09-08 14:04:52 +08:00
|
|
|
|
|
|
|
<path>...::
|
2006-12-14 16:03:18 +08:00
|
|
|
The <paths> parameters, when given, are used to limit
|
|
|
|
the diff to the named paths (you can give directory
|
|
|
|
names and get diff for all files under them).
|
2005-08-23 16:49:47 +08:00
|
|
|
|
2009-07-28 16:32:18 +08:00
|
|
|
|
2007-10-31 21:59:16 +08:00
|
|
|
include::diff-format.txt[]
|
2005-08-23 16:49:47 +08:00
|
|
|
|
2005-12-13 17:54:15 +08:00
|
|
|
EXAMPLES
|
|
|
|
--------
|
|
|
|
|
|
|
|
Various ways to check your working tree::
|
|
|
|
+
|
|
|
|
------------
|
2006-04-28 21:15:05 +08:00
|
|
|
$ git diff <1>
|
2006-12-13 17:33:43 +08:00
|
|
|
$ git diff --cached <2>
|
2006-04-28 21:15:05 +08:00
|
|
|
$ git diff HEAD <3>
|
|
|
|
------------
|
|
|
|
+
|
2007-08-01 23:43:06 +08:00
|
|
|
<1> Changes in the working tree not yet staged for the next commit.
|
|
|
|
<2> Changes between the index and your last commit; what you
|
2005-12-13 17:54:15 +08:00
|
|
|
would be committing if you run "git commit" without "-a" option.
|
2007-08-01 23:43:06 +08:00
|
|
|
<3> Changes in the working tree since your last commit; what you
|
2005-12-13 17:54:15 +08:00
|
|
|
would be committing if you run "git commit -a"
|
|
|
|
|
|
|
|
Comparing with arbitrary commits::
|
|
|
|
+
|
|
|
|
------------
|
2006-04-28 21:15:05 +08:00
|
|
|
$ git diff test <1>
|
|
|
|
$ git diff HEAD -- ./test <2>
|
|
|
|
$ git diff HEAD^ HEAD <3>
|
|
|
|
------------
|
|
|
|
+
|
2007-08-01 23:43:06 +08:00
|
|
|
<1> Instead of using the tip of the current branch, compare with the
|
2005-12-13 17:54:15 +08:00
|
|
|
tip of "test" branch.
|
2007-08-01 23:43:06 +08:00
|
|
|
<2> Instead of comparing with the tip of "test" branch, compare with
|
2005-12-29 17:20:06 +08:00
|
|
|
the tip of the current branch, but limit the comparison to the
|
2005-12-13 17:54:15 +08:00
|
|
|
file "test".
|
2007-08-01 23:43:06 +08:00
|
|
|
<3> Compare the version before the last commit and the last commit.
|
2005-12-13 17:54:15 +08:00
|
|
|
|
2007-08-28 13:05:19 +08:00
|
|
|
Comparing branches::
|
|
|
|
+
|
|
|
|
------------
|
|
|
|
$ git diff topic master <1>
|
|
|
|
$ git diff topic..master <2>
|
|
|
|
$ git diff topic...master <3>
|
|
|
|
------------
|
|
|
|
+
|
|
|
|
<1> Changes between the tips of the topic and the master branches.
|
|
|
|
<2> Same as above.
|
2007-10-10 05:00:03 +08:00
|
|
|
<3> Changes that occurred on the master branch since when the topic
|
2007-08-28 13:05:19 +08:00
|
|
|
branch was started off it.
|
2005-12-13 17:54:15 +08:00
|
|
|
|
|
|
|
Limiting the diff output::
|
|
|
|
+
|
|
|
|
------------
|
2006-04-28 21:15:05 +08:00
|
|
|
$ git diff --diff-filter=MRC <1>
|
2007-07-29 08:24:27 +08:00
|
|
|
$ git diff --name-status <2>
|
2006-04-28 21:15:05 +08:00
|
|
|
$ git diff arch/i386 include/asm-i386 <3>
|
|
|
|
------------
|
|
|
|
+
|
2007-08-01 23:43:06 +08:00
|
|
|
<1> Show only modification, rename and copy, but not addition
|
2005-12-13 17:54:15 +08:00
|
|
|
nor deletion.
|
2007-08-01 23:43:06 +08:00
|
|
|
<2> Show only names and the nature of change, but not actual
|
2007-07-29 08:24:27 +08:00
|
|
|
diff output.
|
2007-08-01 23:43:06 +08:00
|
|
|
<3> Limit diff output to named subtrees.
|
2005-12-13 17:54:15 +08:00
|
|
|
|
|
|
|
Munging the diff output::
|
|
|
|
+
|
|
|
|
------------
|
2006-04-28 21:15:05 +08:00
|
|
|
$ git diff --find-copies-harder -B -C <1>
|
|
|
|
$ git diff -R <2>
|
|
|
|
------------
|
|
|
|
+
|
2007-08-01 23:43:06 +08:00
|
|
|
<1> Spend extra cycles to find renames, copies and complete
|
2005-12-13 17:54:15 +08:00
|
|
|
rewrites (very expensive).
|
2007-08-01 23:43:06 +08:00
|
|
|
<2> Output diff in reverse.
|
2005-12-13 17:54:15 +08:00
|
|
|
|
2010-01-10 12:02:43 +08:00
|
|
|
SEE ALSO
|
|
|
|
--------
|
|
|
|
linkgit:git-difftool[1]::
|
|
|
|
Show changes using common diff tools
|
2005-12-13 17:54:15 +08:00
|
|
|
|
2005-08-23 16:49:47 +08:00
|
|
|
Author
|
|
|
|
------
|
|
|
|
Written by Linus Torvalds <torvalds@osdl.org>
|
|
|
|
|
|
|
|
Documentation
|
|
|
|
--------------
|
|
|
|
Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
|
|
|
|
|
|
|
|
GIT
|
|
|
|
---
|
2008-06-06 15:07:32 +08:00
|
|
|
Part of the linkgit:git[1] suite
|