* Re: [PATCH v1] diff: document -U without <n> as using default context
2026-03-09 17:27 ` [PATCH v1] diff: document -U without <n> as using default context Tian Yuchen
@ 2026-03-09 22:00 ` D. Ben Knoble
2026-03-10 4:55 ` Tian Yuchen
2026-03-09 22:17 ` Junio C Hamano
` (3 subsequent siblings)
4 siblings, 1 reply; 14+ messages in thread
From: D. Ben Knoble @ 2026-03-09 22:00 UTC (permalink / raw)
To: Tian Yuchen; +Cc: git, gitster
On Mon, Mar 9, 2026 at 1:28 PM Tian Yuchen <cat@malon.dev> wrote:
>
> The documentation for '-U<n>' implies that the numeric value '<n>' is
> mandatory. However, the command line parser has historically accepted
> '-U' without a number.
>
> Strictly requiring a number for '-U' would break existing tests
> (e.g., in 't4013') and likely disrupt user scripts relying on this
> undocumented behavior.
>
> Since we are retaining this fallback behavior for backward compatibility,
> update the documentation to explicitly state that '<n>' can be omitted
> for the short option '-U'.
>
> Signed-off-by: Tian Yuchen <cat@malon.dev>
> ---
> Documentation/diff-context-options.adoc | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/Documentation/diff-context-options.adoc b/Documentation/diff-context-options.adoc
> index e161260358..655496ec3a 100644
> --- a/Documentation/diff-context-options.adoc
> +++ b/Documentation/diff-context-options.adoc
> @@ -1,4 +1,4 @@
> -`-U<n>`::
> +`-U[<n>]`::
> `--unified=<n>`::
> Generate diffs with _<n>_ lines of context. Defaults to `diff.context`
> or 3 if the config option is unset.
> --
> 2.43.0
I was curious about the way we indicate this kind of optionality for
single-letter options, so:
git grep -e '-[[:alnum:]]\[' Documentation
which finds many hits of this pattern. Cool. Adding -A1, we see that
it is also common to document the long-form like
--unified[=<n>]
which you may want to add to this patch. (I haven't really considered
the rest of it very well, although it does seem worth updating the
syntax to match what some of our tests exercise.)
Which makes me notice: 3 is the default if the config option is unset
_or_ if <n> is not provided. Is there a better wording to indicate
that? Maybe the simplest tweak is to clarify that <n> is the thing
which defaults to… (since a first read might leave the reader
wondering "what defaults to diff.context or 3? ah, it's probably n…").
But a glance at other docs makes this pattern seem common while some
do say "if <n> is specified…", so idk.
BTW I noticed these docs are duplicated between
Documentation/diff-{,context-}options.adoc
--
D. Ben Knoble
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH v1] diff: document -U without <n> as using default context
2026-03-09 22:00 ` D. Ben Knoble
@ 2026-03-10 4:55 ` Tian Yuchen
0 siblings, 0 replies; 14+ messages in thread
From: Tian Yuchen @ 2026-03-10 4:55 UTC (permalink / raw)
To: D. Ben Knoble; +Cc: git, gitster
Hi Ben,
On 3/10/26 06:00, D. Ben Knoble wrote:
> Which makes me notice: 3 is the default if the config option is unset
> _or_ if <n> is not provided. Is there a better wording to indicate
> that? Maybe the simplest tweak is to clarify that <n> is the thing
> which defaults to… (since a first read might leave the reader
> wondering "what defaults to diff.context or 3? ah, it's probably n…").
> But a glance at other docs makes this pattern seem common while some
> do say "if <n> is specified…", so idk.
Indeed, the current wording isn't clear enough. I'll make corrections
wherever it's needed. I think Junio provides a good template that's
great with just a few tweaks ;)
Thanks for the review!
Yuchen
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v1] diff: document -U without <n> as using default context
2026-03-09 17:27 ` [PATCH v1] diff: document -U without <n> as using default context Tian Yuchen
2026-03-09 22:00 ` D. Ben Knoble
@ 2026-03-09 22:17 ` Junio C Hamano
2026-03-10 4:51 ` Tian Yuchen
2026-03-10 5:30 ` [PATCH v2] " Tian Yuchen
` (2 subsequent siblings)
4 siblings, 1 reply; 14+ messages in thread
From: Junio C Hamano @ 2026-03-09 22:17 UTC (permalink / raw)
To: Tian Yuchen; +Cc: git
Tian Yuchen <cat@malon.dev> writes:
> The documentation for '-U<n>' implies that the numeric value '<n>' is
> mandatory. However, the command line parser has historically accepted
> '-U' without a number.
>
> Strictly requiring a number for '-U' would break existing tests
> (e.g., in 't4013') and likely disrupt user scripts relying on this
> undocumented behavior.
>
> Since we are retaining this fallback behavior for backward compatibility,
> update the documentation to explicitly state that '<n>' can be omitted
> for the short option '-U'.
>
> Signed-off-by: Tian Yuchen <cat@malon.dev>
> ---
> Documentation/diff-context-options.adoc | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
I am moderately nagative.
It is not like we are _encouraging_ users to omit <n> from -U<n>,
but it is not errored out only due to a bug. Who would the new text
help? Users would wonder why <n> is not optional in --unified=<n>,
the other way to spell the same thing.
If we want to be explicit, we should probably do this instead:
`-U<n>`::
`--unified=<n>`::
Generate diffs with _<n>_ lines of context. Defaults to `diff.context`
or 3 if the config option is unset (`-U` without '<n>' is accepted
as a silent synonym for `-p` due to a historical accident).
which would tell readers what happens when '<n>' is omitted and why
we allow such an inconsistency.
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH v1] diff: document -U without <n> as using default context
2026-03-09 22:17 ` Junio C Hamano
@ 2026-03-10 4:51 ` Tian Yuchen
0 siblings, 0 replies; 14+ messages in thread
From: Tian Yuchen @ 2026-03-10 4:51 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Hi Junio,
> I am moderately nagative.
>
> It is not like we are _encouraging_ users to omit <n> from -U<n>,
> but it is not errored out only due to a bug. Who would the new text
> help? Users would wonder why <n> is not optional in --unified=<n>,
> the other way to spell the same thing.
Indeed.
What I was actually thinking earlier was: for bugs like this, which most
likely come from misoperations, typos, or inconsistencies from *ancient*
standards, should we acknowledge them as
“yes it is a bug/historical issue”
or
“*special behavior* we defined”?
I'm not as familiar with the Git codebase as you are, so I couldn't make
a definitive call. I chose the second approach, but I now agree the
first makes more sense. In other words, users shouldn't be *encouraged*
to engage in such behavior, right?
> If we want to be explicit, we should probably do this instead:
>
> `-U<n>`::
> `--unified=<n>`::
> Generate diffs with _<n>_ lines of context. Defaults to `diff.context`
> or 3 if the config option is unset (`-U` without '<n>' is accepted
> as a silent synonym for `-p` due to a historical accident).
>
> which would tell readers what happens when '<n>' is omitted and why
> we allow such an inconsistency.
That makes sense. I'll make the changes accordingly.
Regards,
Yuchen
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v2] diff: document -U without <n> as using default context
2026-03-09 17:27 ` [PATCH v1] diff: document -U without <n> as using default context Tian Yuchen
2026-03-09 22:00 ` D. Ben Knoble
2026-03-09 22:17 ` Junio C Hamano
@ 2026-03-10 5:30 ` Tian Yuchen
2026-03-10 9:15 ` Oswald Buddenhagen
2026-03-10 9:50 ` [PATCH v3] " Tian Yuchen
2026-03-10 17:31 ` [PATCH v1] " Jean-Noël AVILA
4 siblings, 1 reply; 14+ messages in thread
From: Tian Yuchen @ 2026-03-10 5:30 UTC (permalink / raw)
To: git; +Cc: gitster, ben.knoble, Tian Yuchen
The documentation for '-U<n>' implies that the numeric value '<n>' is
mandatory. However, the command line parser has historically accepted
'-U' without a number.
Strictly requiring a number for '-U' would break existing tests
(e.g., in 't4013') and likely disrupt user scripts relying on this
undocumented behavior.
Since we are retaining this fallback behavior for backward compatibility,
update the documentation to explicitly state that '<n>' can be omitted
for the short option '-U'.
Signed-off-by: Tian Yuchen <cat@malon.dev>
---
Documentation/diff-context-options.adoc | 6 ++++--
Documentation/diff-options.adoc | 6 ++++--
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/Documentation/diff-context-options.adoc b/Documentation/diff-context-options.adoc
index e161260358..42d29a0c00 100644
--- a/Documentation/diff-context-options.adoc
+++ b/Documentation/diff-context-options.adoc
@@ -1,7 +1,9 @@
`-U<n>`::
`--unified=<n>`::
- Generate diffs with _<n>_ lines of context. Defaults to `diff.context`
- or 3 if the config option is unset.
+ Generate diffs with _<n>_ lines of context. The number of context
+ lines defaults to `diff.context` or 3 if the config option is unset.
+ (`-U` without `<n>` is accepted as a silent synonym for `-p` due
+ to a historical accident).
`--inter-hunk-context=<n>`::
Show the context between diff hunks, up to the specified _<number>_
diff --git a/Documentation/diff-options.adoc b/Documentation/diff-options.adoc
index 9cdad6f72a..40502639a2 100644
--- a/Documentation/diff-options.adoc
+++ b/Documentation/diff-options.adoc
@@ -127,8 +127,10 @@ endif::git-log[]
`-U<n>`::
`--unified=<n>`::
- Generate diffs with _<n>_ lines of context instead of
- the usual three.
+ Generate diffs with _<n>_ lines of context. The number of context
+ lines defaults to `diff.context` or 3 if the config option is unset.
+ (`-U` without `<n>` is accepted as a silent synonym for `-p` due
+ to a historical accident).
ifndef::git-format-patch[]
Implies `--patch`.
endif::git-format-patch[]
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v2] diff: document -U without <n> as using default context
2026-03-10 5:30 ` [PATCH v2] " Tian Yuchen
@ 2026-03-10 9:15 ` Oswald Buddenhagen
2026-03-10 9:43 ` Tian Yuchen
2026-03-10 13:14 ` Junio C Hamano
0 siblings, 2 replies; 14+ messages in thread
From: Oswald Buddenhagen @ 2026-03-10 9:15 UTC (permalink / raw)
To: Tian Yuchen; +Cc: git, gitster, ben.knoble
On Tue, Mar 10, 2026 at 01:30:32PM +0800, Tian Yuchen wrote:
>The documentation for '-U<n>' implies that the numeric value '<n>' is
>mandatory. However, the command line parser has historically accepted
>'-U' without a number.
>
>Strictly requiring a number for '-U' would break existing tests
>(e.g., in 't4013') and likely disrupt user scripts relying on this
>undocumented behavior.
>Since we are retaining this fallback behavior for backward compatibility,
>update the documentation to explicitly state that '<n>' can be omitted
>for the short option '-U'.
>
i'd replace that with:
Hence we retain this fallback behavior for backward compatibility, but
document it as such.
>+ (`-U` without `<n>` is accepted as a silent synonym for `-p` due
>+ to a historical accident).
>
"silently accepted as a synonym" would be much more natural.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2] diff: document -U without <n> as using default context
2026-03-10 9:15 ` Oswald Buddenhagen
@ 2026-03-10 9:43 ` Tian Yuchen
2026-03-10 13:14 ` Junio C Hamano
1 sibling, 0 replies; 14+ messages in thread
From: Tian Yuchen @ 2026-03-10 9:43 UTC (permalink / raw)
To: Oswald Buddenhagen; +Cc: git, gitster, ben.knoble
On 3/10/26 17:15, Oswald Buddenhagen wrote:
> i'd replace that with:
>
> Hence we retain this fallback behavior for backward compatibility, but
> document it as such.
>
>> + (`-U` without `<n>` is accepted as a silent synonym for `-p` due
>> + to a historical accident).
>>
> "silently accepted as a synonym" would be much more natural.
Thank you for pointing out. This change does make the message read more
smoothly.
Will send v3 shortly.
Yuchen
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2] diff: document -U without <n> as using default context
2026-03-10 9:15 ` Oswald Buddenhagen
2026-03-10 9:43 ` Tian Yuchen
@ 2026-03-10 13:14 ` Junio C Hamano
1 sibling, 0 replies; 14+ messages in thread
From: Junio C Hamano @ 2026-03-10 13:14 UTC (permalink / raw)
To: Oswald Buddenhagen; +Cc: Tian Yuchen, git, ben.knoble
Oswald Buddenhagen <oswald.buddenhagen@gmx.de> writes:
>>Since we are retaining this fallback behavior for backward compatibility,
>>update the documentation to explicitly state that '<n>' can be omitted
>>for the short option '-U'.
>>
> i'd replace that with:
>
> Hence we retain this fallback behavior for backward compatibility, but
> document it as such.
>
>>+ (`-U` without `<n>` is accepted as a silent synonym for `-p` due
>>+ to a historical accident).
>>
> "silently accepted as a synonym" would be much more natural.
An excellent suggestion. Thanks.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v3] diff: document -U without <n> as using default context
2026-03-09 17:27 ` [PATCH v1] diff: document -U without <n> as using default context Tian Yuchen
` (2 preceding siblings ...)
2026-03-10 5:30 ` [PATCH v2] " Tian Yuchen
@ 2026-03-10 9:50 ` Tian Yuchen
2026-03-10 17:31 ` [PATCH v1] " Jean-Noël AVILA
4 siblings, 0 replies; 14+ messages in thread
From: Tian Yuchen @ 2026-03-10 9:50 UTC (permalink / raw)
To: git; +Cc: gitster, ben.knoble, oswald.buddenhagen, Tian Yuchen
The documentation for '-U<n>' implies that the numeric value '<n>' is
mandatory. However, the command line parser has historically accepted
'-U' without a number.
Strictly requiring a number for '-U' would break existing tests
(e.g., in 't4013') and likely disrupt user scripts relying on this
undocumented behavior.
Hence we retain this fallback behavior for backward compatibility, but
document it as such.
Signed-off-by: Tian Yuchen <cat@malon.dev>
---
Documentation/diff-context-options.adoc | 6 ++++--
Documentation/diff-options.adoc | 6 ++++--
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/Documentation/diff-context-options.adoc b/Documentation/diff-context-options.adoc
index e161260358..306abfd9ab 100644
--- a/Documentation/diff-context-options.adoc
+++ b/Documentation/diff-context-options.adoc
@@ -1,7 +1,9 @@
`-U<n>`::
`--unified=<n>`::
- Generate diffs with _<n>_ lines of context. Defaults to `diff.context`
- or 3 if the config option is unset.
+ Generate diffs with _<n>_ lines of context. The number of context
+ lines defaults to `diff.context` or 3 if the config option is unset.
+ (`-U` without `<n>` is silently accepted as a synonym for `-p` due
+ to a historical accident).
`--inter-hunk-context=<n>`::
Show the context between diff hunks, up to the specified _<number>_
diff --git a/Documentation/diff-options.adoc b/Documentation/diff-options.adoc
index 9cdad6f72a..e1f20bedf6 100644
--- a/Documentation/diff-options.adoc
+++ b/Documentation/diff-options.adoc
@@ -127,8 +127,10 @@ endif::git-log[]
`-U<n>`::
`--unified=<n>`::
- Generate diffs with _<n>_ lines of context instead of
- the usual three.
+ Generate diffs with _<n>_ lines of context. The number of context
+ lines defaults to `diff.context` or 3 if the config option is unset.
+ (`-U` without `<n>` is silently accepted as a synonym for `-p` due
+ to a historical accident).
ifndef::git-format-patch[]
Implies `--patch`.
endif::git-format-patch[]
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v1] diff: document -U without <n> as using default context
2026-03-09 17:27 ` [PATCH v1] diff: document -U without <n> as using default context Tian Yuchen
` (3 preceding siblings ...)
2026-03-10 9:50 ` [PATCH v3] " Tian Yuchen
@ 2026-03-10 17:31 ` Jean-Noël AVILA
2026-03-11 4:33 ` Tian Yuchen
4 siblings, 1 reply; 14+ messages in thread
From: Jean-Noël AVILA @ 2026-03-10 17:31 UTC (permalink / raw)
To: git, Tian Yuchen; +Cc: gitster, Tian Yuchen
On Monday, 9 March 2026 18:27:19 CET Tian Yuchen wrote:
> The documentation for '-U<n>' implies that the numeric value '<n>' is
> mandatory. However, the command line parser has historically accepted
> '-U' without a number.
>
> Strictly requiring a number for '-U' would break existing tests
> (e.g., in 't4013') and likely disrupt user scripts relying on this
> undocumented behavior.
>
> Since we are retaining this fallback behavior for backward compatibility,
> update the documentation to explicitly state that '<n>' can be omitted
> for the short option '-U'.
In this case, isn't the long option also changed to optional number, such as:
`--unified[=<n>]`
?
>
> Signed-off-by: Tian Yuchen <cat@malon.dev>
> ---
> Documentation/diff-context-options.adoc | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/Documentation/diff-context-options.adoc
> b/Documentation/diff-context-options.adoc index e161260358..655496ec3a
100644
> --- a/Documentation/diff-context-options.adoc
> +++ b/Documentation/diff-context-options.adoc
> @@ -1,4 +1,4 @@
> -`-U<n>`::
> +`-U[<n>]`::
> `--unified=<n>`::
> Generate diffs with _<n>_ lines of context. Defaults to
`diff.context`
> or 3 if the config option is unset.
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH v1] diff: document -U without <n> as using default context
2026-03-10 17:31 ` [PATCH v1] " Jean-Noël AVILA
@ 2026-03-11 4:33 ` Tian Yuchen
0 siblings, 0 replies; 14+ messages in thread
From: Tian Yuchen @ 2026-03-11 4:33 UTC (permalink / raw)
To: Jean-Noël AVILA, git; +Cc: gitster
On 3/11/26 01:31, Jean-Noël AVILA wrote:
> In this case, isn't the long option also changed to optional number, such as:
>
> `--unified[=<n>]`
>
> ?
Indeed. Your statement aligns with what Junio said earlier.
>> The documentation for '-U<n>' implies that the numeric value '<n>' is
>> mandatory. However, the command line parser has historically accepted
>> '-U' without a number.
>>
>> Strictly requiring a number for '-U' would break existing tests
>> (e.g., in 't4013') and likely disrupt user scripts relying on this
>> undocumented behavior.
>>
>> Since we are retaining this fallback behavior for backward compatibility,
>> update the documentation to explicitly state that '<n>' can be omitted
>> for the short option '-U'.
>>
>> Signed-off-by: Tian Yuchen <cat@malon.dev>
>> ---
>> Documentation/diff-context-options.adoc | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> I am moderately nagative.
>
> It is not like we are _encouraging_ users to omit <n> from -U<n>,
> but it is not errored out only due to a bug. Who would the new text
> help? Users would wonder why <n> is not optional in --unified=<n>,
> the other way to spell the same thing.
>
> If we want to be explicit, we should probably do this instead:
>
> `-U<n>`::
> `--unified=<n>`::
> Generate diffs with _<n>_ lines of context. Defaults to `diff.context`
> or 3 if the config option is unset (`-U` without '<n>' is accepted
> as a silent synonym for `-p` due to a historical accident).
>
> which would tell readers what happens when '<n>' is omitted and why
> we allow such an inconsistency.
I have already fixed this in the v3 patch.
Thank you,
Yuchen
^ permalink raw reply [flat|nested] 14+ messages in thread