From: kristofferhaugsbakk@fastmail.com
To: git@vger.kernel.org
Cc: Kristoffer Haugsbakk <code@khaugsbakk.name>
Subject: [PATCH 11/12] doc: diff-tree: add Examples section and mention --stdin
Date: Wed, 2 Dec 2026 23:14:19 +0100 [thread overview]
Message-ID: <Examples_--stdin.dfa@m5gid.xyz> (raw)
In-Reply-To: <CV_diff-tree_NUL_termination.def@m5gid.xyz>
From: Kristoffer Haugsbakk <code@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 <code@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
next prev parent reply other threads:[~2026-12-02 22:17 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 22:14 [PATCH 00/12] revision: learn -Z for NUL termination kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 01/12] t4205: use correct 'setup' keyword kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 02/12] t4205: add test coverage for NUL separator and --patch kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 03/12] t4205: test blank line between commit and diff explicitly kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 04/12] t4013-diff-various.sh: test --stdin -z --patch kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 05/12] log-tree: terminate cmt+diff when " kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 06/12] t4205: test --diff-merges kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 07/12] revision: learn -Z for NUL termination kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 08/12] revision: split out termination character kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 09/12] diff-tree: flush each diff when --stdin kristofferhaugsbakk
2026-12-02 22:14 ` [PATCH 10/12] doc: diff-tree: tell about --no-commit-id in Description kristofferhaugsbakk
2026-12-02 22:14 ` kristofferhaugsbakk [this message]
2026-12-02 22:14 ` [PATCH 12/12] doc: rev-list: complete diff-tree by mentioning --always kristofferhaugsbakk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Examples_--stdin.dfa@m5gid.xyz \
--to=kristofferhaugsbakk@fastmail.com \
--cc=code@khaugsbakk.name \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.