2005-09-08 00:26:23 +00:00
|
|
|
git-diff(1)
|
|
|
|
===========
|
2005-08-23 08:49:47 +00:00
|
|
|
|
|
|
|
NAME
|
|
|
|
----
|
2006-03-09 16:24:50 +00:00
|
|
|
git-diff - Show changes between commits, commit and working tree, etc
|
2005-08-23 08:49:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
--------
|
2010-11-04 21:17:29 +00:00
|
|
|
[verse]
|
2018-05-24 20:11:39 +00:00
|
|
|
'git diff' [<options>] [<commit>] [--] [<path>...]
|
2020-09-20 11:22:25 +00:00
|
|
|
'git diff' [<options>] --cached [--merge-base] [<commit>] [--] [<path>...]
|
2020-09-14 18:36:52 +00:00
|
|
|
'git diff' [<options>] [--merge-base] <commit> [<commit>...] <commit> [--] [<path>...]
|
2020-06-12 16:20:00 +00:00
|
|
|
'git diff' [<options>] <commit>...<commit> [--] [<path>...]
|
2018-05-24 20:11:39 +00:00
|
|
|
'git diff' [<options>] <blob> <blob>
|
|
|
|
'git diff' [<options>] --no-index [--] <path> <path>
|
2005-08-23 08:49:47 +00:00
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
-----------
|
2010-11-04 21:17:29 +00:00
|
|
|
Show changes between the working tree and the index or a tree, changes
|
2020-06-12 16:20:00 +00:00
|
|
|
between the index and a tree, changes between two trees, changes resulting
|
|
|
|
from a merge, changes between two blob objects, or changes between two
|
|
|
|
files on disk.
|
2005-09-08 06:04:52 +00:00
|
|
|
|
2018-05-24 20:11:39 +00:00
|
|
|
'git diff' [<options>] [--] [<path>...]::
|
2005-12-05 08:22:01 +00:00
|
|
|
|
2006-12-14 08:03:18 +00:00
|
|
|
This form is to view the changes you made relative to
|
|
|
|
the index (staging area for the next commit). In other
|
2013-01-21 19:17:53 +00:00
|
|
|
words, the differences are what you _could_ tell Git to
|
2006-12-14 08:03:18 +00:00
|
|
|
further add to the index but you still haven't. You can
|
2007-12-29 06:20:38 +00:00
|
|
|
stage these changes by using linkgit:git-add[1].
|
2013-08-28 22:17:18 +00:00
|
|
|
|
2018-05-24 20:11:39 +00:00
|
|
|
'git diff' [<options>] --no-index [--] <path> <path>::
|
2013-08-28 22:17:18 +00:00
|
|
|
|
|
|
|
This form is to compare the given two paths on the
|
|
|
|
filesystem. You can omit the `--no-index` option when
|
|
|
|
running the command in a working tree controlled by Git and
|
|
|
|
at least one of the paths points outside the working tree,
|
|
|
|
or when running the command outside a working tree
|
2019-10-29 16:54:32 +00:00
|
|
|
controlled by Git. This form implies `--exit-code`.
|
2007-02-22 20:50:10 +00:00
|
|
|
|
2020-09-20 11:22:25 +00:00
|
|
|
'git diff' [<options>] --cached [--merge-base] [<commit>] [--] [<path>...]::
|
2006-12-14 08:03:18 +00:00
|
|
|
|
|
|
|
This form is to view the changes you staged for the next
|
2006-12-20 22:41:54 +00:00
|
|
|
commit relative to the named <commit>. Typically you
|
2006-12-14 08:03:18 +00:00
|
|
|
would want comparison with the latest commit, so if you
|
|
|
|
do not give <commit>, it defaults to HEAD.
|
2014-02-05 22:19:43 +00:00
|
|
|
If HEAD does not exist (e.g. unborn branches) and
|
2011-02-03 06:23:34 +00:00
|
|
|
<commit> is not given, it shows all staged changes.
|
2008-10-29 16:15:36 +00:00
|
|
|
--staged is a synonym of --cached.
|
2020-09-20 11:22:25 +00:00
|
|
|
+
|
|
|
|
If --merge-base is given, instead of using <commit>, use the merge base
|
2021-07-10 09:28:31 +00:00
|
|
|
of <commit> and HEAD. `git diff --cached --merge-base A` is equivalent to
|
|
|
|
`git diff --cached $(git merge-base A HEAD)`.
|
2006-12-14 08:03:18 +00:00
|
|
|
|
2021-07-10 09:28:31 +00:00
|
|
|
'git diff' [<options>] [--merge-base] <commit> [--] [<path>...]::
|
2006-12-14 08:03:18 +00: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.
|
2021-07-10 09:28:31 +00:00
|
|
|
+
|
|
|
|
If --merge-base is given, instead of using <commit>, use the merge base
|
|
|
|
of <commit> and HEAD. `git diff --merge-base A` is equivalent to
|
|
|
|
`git diff $(git merge-base A HEAD)`.
|
2006-12-14 08:03:18 +00:00
|
|
|
|
2020-09-14 18:36:52 +00:00
|
|
|
'git diff' [<options>] [--merge-base] <commit> <commit> [--] [<path>...]::
|
2006-12-14 08:03:18 +00:00
|
|
|
|
2007-08-28 05:05:19 +00:00
|
|
|
This is to view the changes between two arbitrary
|
|
|
|
<commit>.
|
2020-09-14 18:36:52 +00:00
|
|
|
+
|
|
|
|
If --merge-base is given, use the merge base of the two commits for the
|
|
|
|
"before" side. `git diff --merge-base A B` is equivalent to
|
|
|
|
`git diff $(git merge-base A B) B`.
|
2007-08-28 05:05:19 +00:00
|
|
|
|
2020-07-13 19:10:08 +00:00
|
|
|
'git diff' [<options>] <commit> <commit>... <commit> [--] [<path>...]::
|
2020-06-12 16:20:00 +00:00
|
|
|
|
|
|
|
This form is to view the results of a merge commit. The first
|
|
|
|
listed <commit> must be the merge itself; the remaining two or
|
2022-10-01 10:28:07 +00:00
|
|
|
more commits should be its parents. Convenient ways to produce
|
|
|
|
the desired set of revisions are to use the suffixes `^@` and
|
|
|
|
`^!`. If A is a merge commit, then `git diff A A^@`,
|
|
|
|
`git diff A^!` and `git show A` all give the same combined diff.
|
2020-06-12 16:20:00 +00:00
|
|
|
|
2020-07-13 19:10:09 +00:00
|
|
|
'git diff' [<options>] <commit>..<commit> [--] [<path>...]::
|
|
|
|
|
2020-09-17 07:44:07 +00:00
|
|
|
This is synonymous to the earlier form (without the `..`) for
|
2020-07-13 19:10:09 +00:00
|
|
|
viewing the changes between two arbitrary <commit>. If <commit> on
|
|
|
|
one side is omitted, it will have the same effect as
|
|
|
|
using HEAD instead.
|
|
|
|
|
2018-05-24 20:11:39 +00:00
|
|
|
'git diff' [<options>] <commit>\...<commit> [--] [<path>...]::
|
2007-08-28 05:05:19 +00:00
|
|
|
|
|
|
|
This form is to view the changes on the branch containing
|
|
|
|
and up to the second <commit>, starting at a common ancestor
|
2020-09-17 07:44:07 +00: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 05:05:19 +00:00
|
|
|
of <commit>, which has the same effect as using HEAD instead.
|
2006-12-14 08:03:18 +00:00
|
|
|
|
2018-10-10 22:26:54 +00:00
|
|
|
Just in case you are doing something exotic, it should be
|
2007-08-29 04:47:08 +00:00
|
|
|
noted that all of the <commit> in the above description, except
|
2020-09-20 11:22:25 +00:00
|
|
|
in the `--merge-base` case and in the last two forms that use `..`
|
Documentation: document AUTO_MERGE
Since 5291828df8 (merge-ort: write $GIT_DIR/AUTO_MERGE whenever we hit a
conflict, 2021-03-20), when using the 'ort' merge strategy, the special
ref AUTO_MERGE is written when a merge operation results in conflicts.
This ref points to a tree recording the conflicted state of the working
tree and is very useful during conflict resolution. However, this ref is
not documented.
Add some documentation for AUTO_MERGE in git-diff(1), git-merge(1),
gitrevisions(7) and in the user manual.
In git-diff(1), mention it at the end of the description section, when
we mention that the command also accepts trees instead of commits, and
also add an invocation to the "Various ways to check your working tree"
example.
In git-merge(1), add a step to the list of things that happen "when it
is not obvious how to reconcile the changes", under the "True merge"
section. Also mention AUTO_MERGE in the "How to resolve conflicts"
section, when mentioning 'git diff'.
In gitrevisions(7), add a mention of AUTO_MERGE along with the other
special refs.
In the user manual, add a paragraph describing AUTO_MERGE to the
"Getting conflict-resolution help during a merge" section, and include
an example of a 'git diff AUTO_MERGE' invocation for the example
conflict used in that section. Note that for uniformity we do not use
backticks around AUTO_MERGE here since the rest of the document does not
typeset special refs differently.
Closes: https://github.com/gitgitgadget/git/issues/1471
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-22 19:29:00 +00:00
|
|
|
notations, can be any <tree>. A tree of interest is the one pointed to
|
|
|
|
by the special ref `AUTO_MERGE`, which is written by the 'ort' merge
|
|
|
|
strategy upon hitting merge conflicts (see linkgit:git-merge[1]).
|
|
|
|
Comparing the working tree with `AUTO_MERGE` shows changes you've made
|
|
|
|
so far to resolve textual conflicts (see the examples below).
|
2005-12-05 08:22:01 +00:00
|
|
|
|
2007-01-18 02:08:09 +00:00
|
|
|
For a more complete list of ways to spell <commit>, see
|
2010-10-11 16:03:32 +00:00
|
|
|
"SPECIFYING REVISIONS" section in linkgit:gitrevisions[7].
|
2007-08-28 05:05:19 +00:00
|
|
|
However, "diff" is about comparing two _endpoints_, not ranges,
|
2020-09-17 07:44:07 +00:00
|
|
|
and the range notations (`<commit>..<commit>` and
|
|
|
|
`<commit>...<commit>`) do not mean a range as defined in the
|
2010-10-11 16:03:32 +00:00
|
|
|
"SPECIFYING RANGES" section in linkgit:gitrevisions[7].
|
2005-08-23 08:49:47 +00:00
|
|
|
|
2018-05-24 20:11:39 +00:00
|
|
|
'git diff' [<options>] <blob> <blob>::
|
2013-06-18 14:58:50 +00:00
|
|
|
|
|
|
|
This form is to view the differences between the raw
|
|
|
|
contents of two blob objects.
|
|
|
|
|
2005-08-23 08:49:47 +00:00
|
|
|
OPTIONS
|
|
|
|
-------
|
2007-11-15 13:19:29 +00:00
|
|
|
:git-diff: 1
|
2006-12-14 08:03:18 +00:00
|
|
|
include::diff-options.txt[]
|
2005-09-08 06:04:52 +00:00
|
|
|
|
2017-04-11 14:39:50 +00:00
|
|
|
-1 --base::
|
|
|
|
-2 --ours::
|
|
|
|
-3 --theirs::
|
|
|
|
Compare the working tree with the "base" version (stage #1),
|
|
|
|
"our branch" (stage #2) or "their branch" (stage #3). The
|
|
|
|
index contains these stages only for unmerged entries i.e.
|
|
|
|
while resolving conflicts. See linkgit:git-read-tree[1]
|
|
|
|
section "3-Way Merge" for detailed information.
|
|
|
|
|
|
|
|
-0::
|
|
|
|
Omit diff output for unmerged entries and just show
|
|
|
|
"Unmerged". Can be used only when comparing the working tree
|
|
|
|
with the index.
|
|
|
|
|
2005-09-08 06:04:52 +00:00
|
|
|
<path>...::
|
2006-12-14 08:03:18 +00: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 08:49:47 +00:00
|
|
|
|
2009-07-28 08:32:18 +00:00
|
|
|
|
2007-10-31 13:59:16 +00:00
|
|
|
include::diff-format.txt[]
|
2005-08-23 08:49:47 +00:00
|
|
|
|
2005-12-13 09:54:15 +00:00
|
|
|
EXAMPLES
|
|
|
|
--------
|
|
|
|
|
|
|
|
Various ways to check your working tree::
|
|
|
|
+
|
|
|
|
------------
|
2006-04-28 13:15:05 +00:00
|
|
|
$ git diff <1>
|
2006-12-13 09:33:43 +00:00
|
|
|
$ git diff --cached <2>
|
2006-04-28 13:15:05 +00:00
|
|
|
$ git diff HEAD <3>
|
Documentation: document AUTO_MERGE
Since 5291828df8 (merge-ort: write $GIT_DIR/AUTO_MERGE whenever we hit a
conflict, 2021-03-20), when using the 'ort' merge strategy, the special
ref AUTO_MERGE is written when a merge operation results in conflicts.
This ref points to a tree recording the conflicted state of the working
tree and is very useful during conflict resolution. However, this ref is
not documented.
Add some documentation for AUTO_MERGE in git-diff(1), git-merge(1),
gitrevisions(7) and in the user manual.
In git-diff(1), mention it at the end of the description section, when
we mention that the command also accepts trees instead of commits, and
also add an invocation to the "Various ways to check your working tree"
example.
In git-merge(1), add a step to the list of things that happen "when it
is not obvious how to reconcile the changes", under the "True merge"
section. Also mention AUTO_MERGE in the "How to resolve conflicts"
section, when mentioning 'git diff'.
In gitrevisions(7), add a mention of AUTO_MERGE along with the other
special refs.
In the user manual, add a paragraph describing AUTO_MERGE to the
"Getting conflict-resolution help during a merge" section, and include
an example of a 'git diff AUTO_MERGE' invocation for the example
conflict used in that section. Note that for uniformity we do not use
backticks around AUTO_MERGE here since the rest of the document does not
typeset special refs differently.
Closes: https://github.com/gitgitgadget/git/issues/1471
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-22 19:29:00 +00:00
|
|
|
$ git diff AUTO_MERGE <4>
|
2006-04-28 13:15:05 +00:00
|
|
|
------------
|
|
|
|
+
|
2007-08-01 15:43:06 +00: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
|
2020-09-17 07:44:07 +00:00
|
|
|
would be committing if you run `git commit` without `-a` option.
|
2007-08-01 15:43:06 +00:00
|
|
|
<3> Changes in the working tree since your last commit; what you
|
2020-09-17 07:44:07 +00:00
|
|
|
would be committing if you run `git commit -a`
|
Documentation: document AUTO_MERGE
Since 5291828df8 (merge-ort: write $GIT_DIR/AUTO_MERGE whenever we hit a
conflict, 2021-03-20), when using the 'ort' merge strategy, the special
ref AUTO_MERGE is written when a merge operation results in conflicts.
This ref points to a tree recording the conflicted state of the working
tree and is very useful during conflict resolution. However, this ref is
not documented.
Add some documentation for AUTO_MERGE in git-diff(1), git-merge(1),
gitrevisions(7) and in the user manual.
In git-diff(1), mention it at the end of the description section, when
we mention that the command also accepts trees instead of commits, and
also add an invocation to the "Various ways to check your working tree"
example.
In git-merge(1), add a step to the list of things that happen "when it
is not obvious how to reconcile the changes", under the "True merge"
section. Also mention AUTO_MERGE in the "How to resolve conflicts"
section, when mentioning 'git diff'.
In gitrevisions(7), add a mention of AUTO_MERGE along with the other
special refs.
In the user manual, add a paragraph describing AUTO_MERGE to the
"Getting conflict-resolution help during a merge" section, and include
an example of a 'git diff AUTO_MERGE' invocation for the example
conflict used in that section. Note that for uniformity we do not use
backticks around AUTO_MERGE here since the rest of the document does not
typeset special refs differently.
Closes: https://github.com/gitgitgadget/git/issues/1471
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-22 19:29:00 +00:00
|
|
|
<4> Changes in the working tree you've made to resolve textual
|
|
|
|
conflicts so far.
|
2005-12-13 09:54:15 +00:00
|
|
|
|
|
|
|
Comparing with arbitrary commits::
|
|
|
|
+
|
|
|
|
------------
|
2006-04-28 13:15:05 +00:00
|
|
|
$ git diff test <1>
|
|
|
|
$ git diff HEAD -- ./test <2>
|
|
|
|
$ git diff HEAD^ HEAD <3>
|
|
|
|
------------
|
|
|
|
+
|
2007-08-01 15:43:06 +00:00
|
|
|
<1> Instead of using the tip of the current branch, compare with the
|
2019-01-22 20:16:35 +00:00
|
|
|
tip of "test" branch.
|
2007-08-01 15:43:06 +00:00
|
|
|
<2> Instead of comparing with the tip of "test" branch, compare with
|
2019-01-22 20:16:35 +00:00
|
|
|
the tip of the current branch, but limit the comparison to the
|
|
|
|
file "test".
|
2007-08-01 15:43:06 +00:00
|
|
|
<3> Compare the version before the last commit and the last commit.
|
2005-12-13 09:54:15 +00:00
|
|
|
|
2007-08-28 05:05:19 +00: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-09 21:00:03 +00:00
|
|
|
<3> Changes that occurred on the master branch since when the topic
|
2019-01-22 20:16:35 +00:00
|
|
|
branch was started off it.
|
2005-12-13 09:54:15 +00:00
|
|
|
|
|
|
|
Limiting the diff output::
|
|
|
|
+
|
|
|
|
------------
|
2006-04-28 13:15:05 +00:00
|
|
|
$ git diff --diff-filter=MRC <1>
|
2007-07-29 00:24:27 +00:00
|
|
|
$ git diff --name-status <2>
|
2006-04-28 13:15:05 +00:00
|
|
|
$ git diff arch/i386 include/asm-i386 <3>
|
|
|
|
------------
|
|
|
|
+
|
2014-03-31 22:11:44 +00:00
|
|
|
<1> Show only modification, rename, and copy, but not addition
|
2019-01-22 20:16:35 +00:00
|
|
|
or deletion.
|
2007-08-01 15:43:06 +00:00
|
|
|
<2> Show only names and the nature of change, but not actual
|
2019-01-22 20:16:35 +00:00
|
|
|
diff output.
|
2007-08-01 15:43:06 +00:00
|
|
|
<3> Limit diff output to named subtrees.
|
2005-12-13 09:54:15 +00:00
|
|
|
|
|
|
|
Munging the diff output::
|
|
|
|
+
|
|
|
|
------------
|
2006-04-28 13:15:05 +00:00
|
|
|
$ git diff --find-copies-harder -B -C <1>
|
|
|
|
$ git diff -R <2>
|
|
|
|
------------
|
|
|
|
+
|
2007-08-01 15:43:06 +00:00
|
|
|
<1> Spend extra cycles to find renames, copies and complete
|
2019-01-22 20:16:35 +00:00
|
|
|
rewrites (very expensive).
|
2007-08-01 15:43:06 +00:00
|
|
|
<2> Output diff in reverse.
|
2005-12-13 09:54:15 +00:00
|
|
|
|
docs: add CONFIGURATION sections that fuzzy map to built-ins
Add a CONFIGURATION section to the documentation of various built-ins,
for those cases where the relevant config/NAME.txt doesn't map only to
one git-NAME.txt. In particular:
* config/blame.txt: used by git-{blame,annotate}.txt. Since the
git-annotate(1) documentation refers to git-blame(1) don't add a
"CONFIGURATION" section to git-annotate(1), only to git-blame(1).
* config/checkout.txt: maps to both git-checkout.txt and
git-switch.txt (but nothing else).
* config/init.txt: should be included in git-init(1) and
git-clone(1).
* config/column.txt: We should ideally mention the relevant subset of
this in git-{branch,clean,status,tag}.txt, but let's punt on it for
now. We will when we eventually split these sort of files into
e.g. config/column.txt and
config/column/{branch,clean,status,tag}.txt, with the former
including the latter set.
Things that are being left out, and why:
* config/{remote,remotes,credential}.txt: Configuration that affects
how we talk to remote repositories is harder to untangle. We'll need
to include some of this in git-{fetch,remote,push,ls-remote}.txt
etc., but some of those only use a small subset of these
options. Let's leave this for now.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Matheus Tavares <matheus.bernardino@usp.br>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-09-07 08:27:05 +00:00
|
|
|
CONFIGURATION
|
|
|
|
-------------
|
|
|
|
|
|
|
|
include::includes/cmd-config-section-all.txt[]
|
|
|
|
|
|
|
|
include::config/diff.txt[]
|
|
|
|
|
2010-01-10 04:02:43 +00:00
|
|
|
SEE ALSO
|
|
|
|
--------
|
2010-10-11 16:05:32 +00:00
|
|
|
diff(1),
|
|
|
|
linkgit:git-difftool[1],
|
|
|
|
linkgit:git-log[1],
|
|
|
|
linkgit:gitdiffcore[7],
|
|
|
|
linkgit:git-format-patch[1],
|
2020-06-12 16:20:00 +00:00
|
|
|
linkgit:git-apply[1],
|
|
|
|
linkgit:git-show[1]
|
2005-12-13 09:54:15 +00:00
|
|
|
|
2005-08-23 08:49:47 +00:00
|
|
|
GIT
|
|
|
|
---
|
2008-06-06 07:07:32 +00:00
|
|
|
Part of the linkgit:git[1] suite
|