blob: a86cf62e68999f698c1a49edab207a9721c6dfaf [file] [log] [blame]
Junio C Hamano215a7ad2005-09-07 17:26:23 -07001git-diff-index(1)
David Greaves2cf565c2005-05-10 22:32:30 +01002=================
David Greaves2cf565c2005-05-10 22:32:30 +01003
4NAME
5----
Junio C Hamanob3d6e6e2013-05-19 22:01:20 -07006git-diff-index - Compare a tree to the working tree or index
David Greaves2cf565c2005-05-10 22:32:30 +01007
8
9SYNOPSIS
10--------
Martin von Zweigbergk7791a1d2011-07-01 22:38:26 -040011[verse]
Jonathan Niederb1889c32008-06-30 01:09:04 -050012'git diff-index' [-m] [--cached] [<common diff options>] <tree-ish> [<path>...]
David Greaves2cf565c2005-05-10 22:32:30 +010013
14DESCRIPTION
15-----------
Junio C Hamanob3d6e6e2013-05-19 22:01:20 -070016Compares the content and mode of the blobs found in a tree object
17with the corresponding tracked files in the working tree, or with the
18corresponding paths in the index. When <path> arguments are present,
19compares only paths matching those patterns. Otherwise all tracked
20files are compared.
David Greaves2cf565c2005-05-10 22:32:30 +010021
22OPTIONS
23-------
Junio C Hamanodda2d792005-07-13 12:52:35 -070024include::diff-options.txt[]
25
David Greaves2cf565c2005-05-10 22:32:30 +010026<tree-ish>::
27 The id of a tree object to diff against.
28
David Greaves2cf565c2005-05-10 22:32:30 +010029--cached::
30 do not consider the on-disk file at all
31
32-m::
33 By default, files recorded in the index but not checked
34 out are reported as deleted. This flag makes
Thomas Rast0b444cd2010-01-10 00:33:00 +010035 'git diff-index' say that all non-checked-out files are up
David Greaves2cf565c2005-05-10 22:32:30 +010036 to date.
37
David Greaves2cf565c2005-05-10 22:32:30 +010038include::diff-format.txt[]
39
40Operating Modes
41---------------
42You can choose whether you want to trust the index file entirely
43(using the '--cached' flag) or ask the diff logic to show any files
44that don't match the stat state as being "tentatively changed". Both
45of these operations are very useful indeed.
46
47Cached Mode
48-----------
49If '--cached' is specified, it allows you to ask:
50
Lukas_Sandström5f3aa192005-11-11 02:12:27 +010051 show me the differences between HEAD and the current index
Thomas Rast0b444cd2010-01-10 00:33:00 +010052 contents (the ones I'd write using 'git write-tree')
David Greaves2cf565c2005-05-10 22:32:30 +010053
Johannes Schindelin2c6e4772005-08-05 17:05:02 +020054For example, let's say that you have worked on your working directory, updated
Junio C Hamano89438672005-12-29 01:20:06 -080055some files in the index and are ready to commit. You want to see exactly
Andy Parkins44b27ec2006-11-02 12:12:44 +010056*what* you are going to commit, without having to write a new tree
Johannes Schindelin2c6e4772005-08-05 17:05:02 +020057object and compare it that way, and to do that, you just do
David Greaves2cf565c2005-05-10 22:32:30 +010058
Jonathan Niederb1889c32008-06-30 01:09:04 -050059 git diff-index --cached HEAD
David Greaves2cf565c2005-05-10 22:32:30 +010060
61Example: let's say I had renamed `commit.c` to `git-commit.c`, and I had
Jonathan Nieder483bc4f2008-06-30 13:56:34 -050062done an `update-index` to make that effective in the index file.
63`git diff-files` wouldn't show anything at all, since the index file
Thomas Rast0b444cd2010-01-10 00:33:00 +010064matches my working directory. But doing a 'git diff-index' does:
David Greaves2cf565c2005-05-10 22:32:30 +010065
Jonathan Niederb1889c32008-06-30 01:09:04 -050066 torvalds@ppc970:~/git> git diff-index --cached HEAD
David Greaves2cf565c2005-05-10 22:32:30 +010067 -100644 blob 4161aecc6700a2eb579e842af0b7f22b98443f74 commit.c
68 +100644 blob 4161aecc6700a2eb579e842af0b7f22b98443f74 git-commit.c
69
Andy Parkins44b27ec2006-11-02 12:12:44 +010070You can see easily that the above is a rename.
David Greaves2cf565c2005-05-10 22:32:30 +010071
Jonathan Nieder483bc4f2008-06-30 13:56:34 -050072In fact, `git diff-index --cached` *should* always be entirely equivalent to
Thomas Rast0b444cd2010-01-10 00:33:00 +010073actually doing a 'git write-tree' and comparing that. Except this one is much
David Greaves2cf565c2005-05-10 22:32:30 +010074nicer for the case where you just want to check where you are.
75
Thomas Rast0b444cd2010-01-10 00:33:00 +010076So doing a `git diff-index --cached` is basically very useful when you are
Junio C Hamanoa6080a02007-06-07 00:04:01 -070077asking yourself "what have I already marked for being committed, and
David Greaves2cf565c2005-05-10 22:32:30 +010078what's the difference to a previous tree".
79
80Non-cached Mode
81---------------
82The "non-cached" mode takes a different approach, and is potentially
83the more useful of the two in that what it does can't be emulated with
Thomas Rast0b444cd2010-01-10 00:33:00 +010084a 'git write-tree' + 'git diff-tree'. Thus that's the default mode.
David Greaves2cf565c2005-05-10 22:32:30 +010085The non-cached version asks the question:
86
Jonas Fonsecadf8baa42005-10-03 19:16:30 +020087 show me the differences between HEAD and the currently checked out
88 tree - index contents _and_ files that aren't up-to-date
David Greaves2cf565c2005-05-10 22:32:30 +010089
90which is obviously a very useful question too, since that tells you what
Thomas Rast0b444cd2010-01-10 00:33:00 +010091you *could* commit. Again, the output matches the 'git diff-tree -r'
David Greaves2cf565c2005-05-10 22:32:30 +010092output to a tee, but with a twist.
93
Lukas_Sandström5f3aa192005-11-11 02:12:27 +010094The twist is that if some file doesn't match the index, we don't have
David Greaves2cf565c2005-05-10 22:32:30 +010095a backing store thing for it, and we use the magic "all-zero" sha1 to
96show that. So let's say that you have edited `kernel/sched.c`, but
Thomas Rast0b444cd2010-01-10 00:33:00 +010097have not actually done a 'git update-index' on it yet - there is no
David Greaves2cf565c2005-05-10 22:32:30 +010098"object" associated with the new state, and you get:
99
Jeff King62b42d32011-05-26 22:33:15 -0400100 torvalds@ppc970:~/v2.6/linux> git diff-index --abbrev HEAD
101 :100644 100664 7476bb... 000000... kernel/sched.c
David Greaves2cf565c2005-05-10 22:32:30 +0100102
Horst H. von Brandabda1ef2006-06-03 16:27:26 -0400103i.e., it shows that the tree has changed, and that `kernel/sched.c` has is
David Greaves2cf565c2005-05-10 22:32:30 +0100104not up-to-date and may contain new stuff. The all-zero sha1 means that to
105get the real diff, you need to look at the object in the working directory
106directly rather than do an object-to-object diff.
107
Thomas Rast0b444cd2010-01-10 00:33:00 +0100108NOTE: As with other commands of this type, 'git diff-index' does not
David Greaves2cf565c2005-05-10 22:32:30 +0100109actually look at the contents of the file at all. So maybe
110`kernel/sched.c` hasn't actually changed, and it's just that you
111touched it. In either case, it's a note that you need to
Thomas Rast0b444cd2010-01-10 00:33:00 +0100112'git update-index' it to make the index be in sync.
David Greaves2cf565c2005-05-10 22:32:30 +0100113
Jonas Fonsecadf8baa42005-10-03 19:16:30 +0200114NOTE: You can have a mixture of files show up as "has been updated"
David Greaves2cf565c2005-05-10 22:32:30 +0100115and "is still dirty in the working directory" together. You can always
116tell which file is in which state, since the "has been updated" ones
117show a valid sha1, and the "not in sync with the index" ones will
118always have the special all-zero sha1.
119
David Greaves2cf565c2005-05-10 22:32:30 +0100120GIT
121---
Christian Couder9e1f0a82008-06-06 09:07:32 +0200122Part of the linkgit:git[1] suite