From: Kristoffer Haugsbakk <co…@khaugsbakk.name>
We added option -Z a few commits ago.[1] This option can be used by
any command that uses revision.c:handle_revision_opt(...), but I had in
mind git-diff-tree(1) in particular. That is because 'git diff-tree
--stdin' outputs each record (commit or diff or both) immediately after
it is processed. That is unlike git-rev-list(1)/git-show(1)/git-log(1)
which wait until stdin is closed to and then outputs everything.
† 1: commit “revision: learn -Z (NUL termination)”
And this behavior is useful for feeding commit IDs, getting back some
output, acting on it, and then feeding the next commit ID. This is
facilitated by using -z so that you know a record is done after you
read it. However, this does not work well for the default separator
case; the delimiter is added *between* records, an in turn you have to
give the Nth commit in order to get the NUL delimiter for the N-1
commit. Also, the last commit is not terminated.
However, with the new -Z option you can pretty-print
commits on demand just like 'git format-rev --stdin-mode=revs':
git cat-file --batch-command='%(objectname)' |
git diff-tree --no-patch --format=<fmt> --always -Z --stdin
And you also get log-tree.c formatted output (e.g. 'Notes:' in
--format=medium) just like commands like git-log(1). And you can do
the same for diffs, or combine commits and diffs with --format=<fmt>
--patch.
Signed-off-by: Kristoffer Haugsbakk <co…@khaugsbakk.name>
---
Documentation/git-diff-tree.adoc | 40 ++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/Documentation/git-diff-tree.adoc b/Documentation/git-diff-tree.adoc
index 084be99e7cf..b73cf4d268d 100644
--- a/Documentation/git-diff-tree.adoc
+++ b/Documentation/git-diff-tree.adoc
@@ -25,6 +25,8 @@ This command outputs a line with the commit ID when applicable. Use
Note that 'git diff-tree' can use the tree encapsulated in a commit object.
+See the "EXAMPLES" section at the end for a few examples.
+
OPTIONS
-------
include::diff-options.adoc[]
@@ -129,6 +131,44 @@ include::pretty-formats.adoc[]
include::diff-format.adoc[]
+EXAMPLES
+--------
+
+The default behavior is to show the commit ID and then the raw diff (see
+`--raw`):
+
+----
+$ git diff-tree HEAD
+00645eb9f4e515533cdf67376d481ffb4a796bcc
+:040000 040000 ac1844364599b5671e9e4da68eab0817cab2ac2d b39de8e87a84787fb7bc2b38e015540e6d336eae M Documentation
+----
+
+But you can use this command to show normal diffs (`--patch`) and commit
+messages as well. You can for example get the same output as `git log`
+with:
+
+----
+$ git rev-list HEAD |
+git diff-tree --no-patch --stdin --always --format=medium
+----
+
+The above is of course longer to type and uses two processes instead
+of two. But this longer form with `--stdin` is more flexible than `git
+log --stdin`. That is because the linkgit:git-log[1] form only outputs
+anything after you close standard in (stdin). Meanwhile, `git diff-tree
+--stdin ...` outputs each commit or diff (or both) immediately. This
+means that you can use `-Z` to feed the commit, handle the output, and
+then continue with the next commit. The above can be tweaked to for
+example show the diff as well with `--patch`.
+
+----
+$ git diff-tree --no-patch --stdin --always --format=<fmt> -Z
+ [rev-list options]
+----
+
+The command `git diff-tree --stdin --patch` can be used together with
+linkgit:git-patch-id[1] to create a map from commit IDs to pach IDs.
+
GIT
---
Part of the linkgit:git[1] suite
--
2.56.1.5.g155936fbb2a