From: "Michael Montalbo via GitGitGadget" <gitgitgadget@gmail•com>
To: git@vger•kernel.org
Cc: Michael Montalbo <mmontalbo@gmail•com>,
Michael Montalbo <mmontalbo@gmail•com>
Subject: [PATCH v2] doc: clarify that --word-diff operates on line-level hunks
Date: Thu, 28 May 2026 19:21:45 +0000 [thread overview]
Message-ID: <pull.2113.v2.git.1779996106005.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2113.git.1778686956622.gitgitgadget@gmail.com>
From: Michael Montalbo <mmontalbo@gmail•com>
The --word-diff documentation describes the output modes and
word-regex mechanics but does not explain that word-diff operates
within the hunks produced by the line-level diff rather than
performing an independent word-stream comparison. This can
surprise users when the line-level alignment causes word-level
changes to appear even though the words in both files are
identical.
Add an implementation note explaining the two-stage relationship
and that the output may change if Git acquires a different
implementation in the future.
Signed-off-by: Michael Montalbo <mmontalbo@gmail•com>
---
doc: clarify that --word-diff operates on line-level hunks
CC: Vincent Lefevre vincent@vinc17•net, Johannes Sixt j6t@kdbg•org
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2113%2Fmmontalbo%2Fmm%2Fdoc-word-diff-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2113/mmontalbo/mm/doc-word-diff-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/2113
Range-diff vs v1:
1: 73f7b06c06 ! 1: bc5ca5a147 doc: clarify that --word-diff operates on line-level hunks
@@ Commit message
changes to appear even though the words in both files are
identical.
- Add a short note explaining the two-stage relationship.
+ Add an implementation note explaining the two-stage relationship
+ and that the output may change if Git acquires a different
+ implementation in the future.
Signed-off-by: Michael Montalbo <mmontalbo@gmail•com>
@@ Documentation/diff-options.adoc: endif::git-diff[]
Note that despite the name of the first mode, color is used to
highlight the changed parts in all modes if enabled.
++
-+Word diff works by finding word-level changes within each hunk of
-+the line-level diff. The line-level alignment determines which
-+changed lines are compared to each other, which can affect the
-+word-level output.
++The `--word-diff` option operates by taking the same line-by-line
++diff that is produced without the option and computing
++word-by-word changes within each hunk. This may produce a
++larger diff than a dedicated word-diff tool would. If Git
++acquires a different implementation in the future, the output
++may change. Note that this is similar to the `--diff-algorithm`
++option, which may also change the output.
`--word-diff-regex=<regex>`::
Use _<regex>_ to decide what a word is, instead of considering
Documentation/diff-options.adoc | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/Documentation/diff-options.adoc b/Documentation/diff-options.adoc
index 8a63b5e164..c8242e2462 100644
--- a/Documentation/diff-options.adoc
+++ b/Documentation/diff-options.adoc
@@ -457,6 +457,14 @@ endif::git-diff[]
+
Note that despite the name of the first mode, color is used to
highlight the changed parts in all modes if enabled.
++
+The `--word-diff` option operates by taking the same line-by-line
+diff that is produced without the option and computing
+word-by-word changes within each hunk. This may produce a
+larger diff than a dedicated word-diff tool would. If Git
+acquires a different implementation in the future, the output
+may change. Note that this is similar to the `--diff-algorithm`
+option, which may also change the output.
`--word-diff-regex=<regex>`::
Use _<regex>_ to decide what a word is, instead of considering
base-commit: 94f057755b7941b321fd11fec1b2e3ca5313a4e0
--
gitgitgadget
prev parent reply other threads:[~2026-05-28 19:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-13 15:42 [PATCH] doc: clarify that --word-diff operates on line-level hunks Michael Montalbo via GitGitGadget
2026-05-28 19:21 ` Michael Montalbo via GitGitGadget [this message]
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=pull.2113.v2.git.1779996106005.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=mmontalbo@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox