While creating changes is useful, it's even more useful if you
can tell later what changed. The most useful command for this is
another of the diff family, namely git diff-tree.
git diff-tree can be given two arbitrary trees, and it will tell
you the differences between them. Perhaps even more commonly,
though, you can give it just a single commit object, and it will
figure out the parent of that commit itself, and show the
difference directly. Thus, to get the same diff that we've
already seen several times, we can now do
$ git diff-tree -p HEAD
(again, -p
means to show the difference as a human-readable
patch), and it will show what the last commit (in HEAD
) actually
changed.
Note
Here is an ASCII art by Jon Loeliger that illustrates how
various diff-* commands compare things.
diff-tree
+----+
| |
| |
V V
+-----------+
| Object DB |
| Backing |
| Store |
+-----------+
^ ^
| |
| | diff-index --cached
| |
diff-index | V
| +-----------+
| | Index |
| | "cache" |
| +-----------+
| ^
| |
| | diff-files
| |
V V
+-----------+
| Working |
| Directory |
+-----------+
More interestingly, you can also give git diff-tree the --pretty
flag, which tells it to also show the commit message and author
and date of the commit, and you can tell it to show a whole
series of diffs. Alternatively, you can tell it to be "silent",
and not show the diffs at all, but just show the actual commit
message.
In fact, together with the git rev-list program (which generates
a list of revisions), git diff-tree ends up being a veritable
fount of changes. You can emulate git log
, git log -p
, etc. with
a trivial script that pipes the output of git rev-list
to git
diff-tree --stdin
, which was exactly how early versions of git
log
were implemented.