Q: .gitignore and asterisk "*"
Hi!
I think the documentation for gitignore(5) could be improved regarding "*":
It's nor clear whether "*" matches an empty string.
So when I have
foo.log
foo.msgfoo.sh
foo-whatever.log
foo-whetever.msg
Would e.g. "foo*.log" cover all the logs?
The manual says:
• An asterisk "*" matches anything except a slash. The character "?"
matches any one character except "/". The range notation, e.g. [a-zA-Z], can be used to match one of the characters in a range. See fnmatch(3) and the FNM_PATHNAME flag for a more detailed description.
Kind regards,
Ulrich Windl
Quoted 10 lines · Ulrich
I think the documentation for gitignore(5) could be improved regarding "*":
It's nor clear whether "*" matches an empty string.
So when I have
foo.log
foo.msgfoo.sh
foo-whatever.log
foo-whetever.msg
Would e.g. "foo*.log" cover all the logs?
Quoted 6 lines
The manual says:
• An asterisk "*" matches anything except a slash. The character "?"
matches any one character except "/". The range notation, e.g. [a-zA-Z], can be used to match one of the characters in a range. See fnmatch(3) and theFNM_PATHNAMEflag for a more detailed description.
Very good point.
The reference to fnmatch(3) may not make readers to consult the documentation for the library function. The system they are on may not even have "man". fnmatch(3) often refers to glob(7), which typically would say that a '*' (not between brackets) matches any string, including the empty string. The reference to FNM_PATHNAME we have there is an attempt to refer back to fnmatch(3) that would typically say that the wildcard does not match a slash.
How about rewriting the entry like so to reduce external references?
----- >8 -----
Subject: gitignore: rewrite wildcard description
The documentation for '.gitignore' makes reference to fnmatch(3) and FNM_PATHNAME to describe how an asterisk "*" and a question mark "?" behave. Even though it spells out that these wildcard characters do not match a slash, it does not say if an asterisk matches an empty string (it does).
Rewrite the section so that the readers would get a more complete picture without requiring them to know what fnmatch(3) and glob(7) says.
--- Documentation/gitignore.adoc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
Documentation/gitignore.adoc +10 -5
@@ -110,11 +110,16 @@ PATTERN FORMAT and `a/frotz` that is a directory (all paths are relative from the `.gitignore` file). - - An asterisk "`*`" matches anything except a slash. - The character "`?`" matches any one character except "`/`". - The range notation, e.g. `[a-zA-Z]`, can be used to match - one of the characters in a range. See fnmatch(3) and the - FNM_PATHNAME flag for a more detailed description. + - An asterisk "`*`" matches string of any length, and a question mark + "`?`" matches any single character, but these wildcard characters + do not match a slash "`/`". + + - A pair of brackets that enclose characters match one of the listed + characters, and a range notation inside them, e.g., "`[a-zA-Z]`", + would behave as if all the characters in the range were listed there + instead. Wildcard characters "`*`" and "`?`" lose their special + meaning inside a pair of brackets, e.g., "`[*]`" would match an + asterisk and nothing else. - A backslash ("`\`") can be used to escape any character. E.g., "`\*`" matches a literal asterisk (and "`\a`" matches "`a`", even though
Quoted 54 lines · Junio C Hamano
Quoted 10 lines · Ulrich
I think the documentation for gitignore(5) could be improved regarding "*":
It's nor clear whether "*" matches an empty string.
So when I have
foo.log
foo.msgfoo.sh
foo-whatever.log
foo-whetever.msg
Would e.g. "foo*.log" cover all the logs?Quoted 6 lines
The manual says:
• An asterisk "*" matches anything except a slash. The character "?"
matches any one character except "/". The range notation, e.g. [a-zA-Z], can be used to match one of the characters in a range. See fnmatch(3) and theFNM_PATHNAMEflag for a more detailed description.Very good point.
The reference to fnmatch(3) may not make readers to consult the documentation for the library function. The system they are on may not even have "man". fnmatch(3) often refers to glob(7), which typically would say that a '*' (not between brackets) matches any string, including the empty string. The reference to
FNM_PATHNAMEwe have there is an attempt to refer back to fnmatch(3) that would typically say that the wildcard does not match a slash.How about rewriting the entry like so to reduce external references?
----- >8 -----
Subject: gitignore: rewrite wildcard descriptionThe documentation for '.gitignore' makes reference to fnmatch(3) and
FNM_PATHNAMEto describe how an asterisk "*" and a question mark "?" behave. Even though it spells out that these wildcard characters do not match a slash, it does not say if an asterisk matches an empty string (it does).Rewrite the section so that the readers would get a more complete picture without requiring them to know what fnmatch(3) and glob(7) says.
Signed-off-by Junio C Hamano <[email protected]>--- Documentation/gitignore.adoc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)Documentation/gitignore.adoc +0
-0
Documentation/gitignore.adoc PATTERN FORMAT · line 113
Quoted 9 lines
Documentation/gitignore.adoc +1
-5@@ -110,11 +110,16 @@ PATTERN FORMAT and `a/frotz` that is a directory (all paths are relative from the `.gitignore` file). - - An asterisk "`*`" matches anything except a slash. - The character "`?`" matches any one character except "`/`". - The range notation, e.g. `[a-zA-Z]`, can be used to match - one of the characters in a range. See fnmatch(3) and the - FNM_PATHNAME flag for a more detailed description. + - An asterisk "`*`" matches string of any length, and a question mark
It's not unreasonable at all to call the empty string "a string of no length", so it is still a bit ambiguous whether it qualifies as a string of any length. I would suggest s/of any length/of length of zero or more/.
Quoted 12 lines
Documentation/gitignore.adoc +9
-0+ "`?`" matches any single character, but these wildcard characters + do not match a slash "`/`". + + - A pair of brackets that enclose characters match one of the listed + characters, and a range notation inside them, e.g., "`[a-zA-Z]`", + would behave as if all the characters in the range were listed there + instead. Wildcard characters "`*`" and "`?`" lose their special + meaning inside a pair of brackets, e.g., "`[*]`" would match an + asterisk and nothing else. - A backslash ("`\`") can be used to escape any character. E.g., "`\*`" matches a literal asterisk (and "`\a`" matches "`a`", even though
Hi!
I think the original " matches anything except a slash." "kind of suggests" that is has to match "something" (non-zero length) to succeed, while the proposed "string of any length" would include zero-size for me. Still, the latest proposal is just as clear IMHO.
Kind regards,
Ulrich Windl
Klinikum der Universität Regensburg
IT / Infrastruktur
Franz-Josef-Strauß-Allee 11
D-93053 Regensburg
Tel: +49 941 944-13816
Softphone: +49 941 944-801142
FAX: +49 941 944-5882
Quoted 91 lines
-----Original Message-----
From: Tuomas Ahola <[email protected]>
Sent: Tuesday, November 3, 2026 8:33 AM
To: Junio C Hamano <[email protected]>
Cc: Windl, Ulrich <[email protected]>; [email protected]
Subject: [EXT] Re: Q: .gitignore and asterisk "*"Quoted 3 lines · Junio C Hamano
Quoted 1 line · Ulrich
I think the documentation for gitignore(5) could be improved regarding
"*":
Quoted 41 lines
Quoted 9 lines
It's nor clear whether "*" matches an empty string. So when I have
foo.log
foo.msgfoo.sh
foo-whatever.log
foo-whetever.msg
Would e.g. "foo*.log" cover all the logs?Quoted 6 lines
The manual says:
• An asterisk "*" matches anything except a slash. The character "?"
matches any one character except "/". The range notation, e.g. [a-zA-Z], can be used to match one of the characters in a range. See fnmatch(3) and theFNM_PATHNAMEflag for a more detailed description.Very good point.
The reference to fnmatch(3) may not make readers to consult the documentation for the library function. The system they are on may not even have "man". fnmatch(3) often refers to glob(7), which typically would say that a '*' (not between brackets) matches any string, including the empty string. The reference to
FNM_PATHNAMEwe have there is an attempt to refer back to fnmatch(3) that would typically say that the wildcard does not match a slash.How about rewriting the entry like so to reduce external references?
----- >8 -----
Subject: gitignore: rewrite wildcard descriptionThe documentation for '.gitignore' makes reference to fnmatch(3) and
FNM_PATHNAMEto describe how an asterisk "*" and a question mark "?" behave. Even though it spells out that these wildcard characters do not match a slash, it does not say if an asterisk matches an empty string (it does).Rewrite the section so that the readers would get a more complete picture without requiring them to know what fnmatch(3) and glob(7) says.
Review
Quoted 6 lines
Signed-off-by Junio C Hamano <[email protected]>--- Documentation/gitignore.adoc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)(quoted diff) +0
-0w/Documentation/gitignore.adoc
Documentation/gitignore.adoc PATTERN FORMAT · line 113
Quoted 13 lines
index
7979e50f18..671a5a4c99100644Documentation/gitignore.adoc +1
-5@@ -110,11 +110,16 @@ PATTERN FORMAT and `a/frotz` that is a directory (all paths are relative from the `.gitignore` file). - - An asterisk "`*`" matches anything except a slash. - The character "`?`" matches any one character except "`/`". - The range notation, e.g. `[a-zA-Z]`, can be used to match - one of the characters in a range. See fnmatch(3) and the - FNM_PATHNAME flag for a more detailed description. + - An asterisk "`*`" matches string of any length, and a question markIt's not unreasonable at all to call the empty string "a string of no length", so it is still a bit ambiguous whether it qualifies as a string of any length. I would suggest s/of any length/of length of zero or more/.
Quoted 12 lines
Documentation/gitignore.adoc +9
-0+ "`?`" matches any single character, but these wildcard characters + do not match a slash "`/`". + + - A pair of brackets that enclose characters match one of the listed + characters, and a range notation inside them, e.g., "`[a-zA-Z]`", + would behave as if all the characters in the range were listed there + instead. Wildcard characters "`*`" and "`?`" lose their special + meaning inside a pair of brackets, e.g., "`[*]`" would match an + asterisk and nothing else. - A backslash ("`\`") can be used to escape any character. E.g., "`\*`" matches a literal asterisk (and "`\a`" matches "`a`", even though
Quoted 3 lines · Tuomas Ahola
Quoted 1 line · Junio C Hamano
"Windl, Ulrich" <[email protected]> writes:
Please trim the lines that do not have any relevance to what you are going to comment on from your quoted material.
Quoted 10 lines
Documentation/gitignore.adoc PATTERN FORMAT · line 113
Quoted 6 lines
- - An asterisk "
*" matches anything except a slash.Documentation/gitignore.adoc +1
-4- The character "`?`" matches any one character except "`/`". - The range notation, e.g. `[a-zA-Z]`, can be used to match - one of the characters in a range. See fnmatch(3) and the - FNM_PATHNAME flag for a more detailed description. + - An asterisk "`*`" matches string of any length, and a question markIt's not unreasonable at all to call the empty string "a string of no length", so it is still a bit ambiguous whether it qualifies as a string of any length. I would suggest s/of any length/of length of zero or more/.
A string of no length falls within the set of strings of any length, so I do not see any ambiguity there.
"A string of length of zero or more" is a roundabout way to say "any string" as by definition there is no string of negative length. Perhaps that is good enough?
Quoted 20 lines · Junio C Hamano
Quoted 3 lines · Tuomas Ahola
Quoted 1 line · Junio C Hamano
"Windl, Ulrich" <[email protected]> writes:
Please trim the lines that do not have any relevance to what you are going to comment on from your quoted material.
Quoted 10 lines
Documentation/gitignore.adoc PATTERN FORMAT · line 113
Quoted 6 lines
- - An asterisk "
*" matches anything except a slash.Documentation/gitignore.adoc +1
-4- The character "`?`" matches any one character except "`/`". - The range notation, e.g. `[a-zA-Z]`, can be used to match - one of the characters in a range. See fnmatch(3) and the - FNM_PATHNAME flag for a more detailed description. + - An asterisk "`*`" matches string of any length, and a question markIt's not unreasonable at all to call the empty string "a string of no length", so it is still a bit ambiguous whether it qualifies as a string of any length. I would suggest s/of any length/of length of zero or more/.
Quoted 6 lines
A string of no length falls within the set of strings of any length, so I do not see any ambiguity there.
"A string of length of zero or more" is a roundabout way to say "any string" as by definition there is no string of negative length. Perhaps that is good enough?
As you wish, although I would like to point that both Linux and BSD versions of glob(7) are quite explicit in their wording:
A '*' (not between brackets) matches any string, including the empty string.
and
* Matches any sequence of zero or more characters.
(Just thinking aloud.)
PATCH v2 1/1 gitignore: rewrite wildcard description
In reply to Junio C HamanoThe documentation for '.gitignore' makes reference to fnmatch(3) and FNM_PATHNAME to describe how an asterisk "*" and a question mark "?" behave. Even though it spells out that these wildcard characters do not match a slash, it does not say if an asterisk matches an empty string (it does).
Rewrite the section so that the readers would get a more complete picture without requiring them to know what fnmatch(3) and glob(7) says.
---
* let's adopt the most explicit "(including the empty string)" from glob(7).
Documentation/gitignore.adoc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
Documentation/gitignore.adoc +10 -5
@@ -110,11 +110,16 @@ PATTERN FORMAT and `a/frotz` that is a directory (all paths are relative from the `.gitignore` file). - - An asterisk "`*`" matches anything except a slash. - The character "`?`" matches any one character except "`/`". - The range notation, e.g. `[a-zA-Z]`, can be used to match - one of the characters in a range. See fnmatch(3) and the - FNM_PATHNAME flag for a more detailed description. + - An asterisk "`*`" matches any string (including the empty string), + and a question mark "`?`" matches any single character, but these + wildcard characters do not match a slash "`/`". + + - A pair of brackets that enclose characters match one of the listed + characters, and a range notation inside them, e.g., "`[a-zA-Z]`", + would behave as if all the characters in the range were listed there + instead. Wildcard characters "`*`" and "`?`" lose their special + meaning inside a pair of brackets, e.g., "`[*]`" would match an + asterisk and nothing else. - A backslash ("`\`") can be used to escape any character. E.g., "`\*`" matches a literal asterisk (and "`\a`" matches "`a`", even though
Interdiff:
diff --git a/Documentation/gitignore.adoc b/Documentation/gitignore.adoc index 671a5a4c99..87f37c2b0c 100644
--- a/Documentation/gitignore.adoc
+++ b/Documentation/gitignore.adoc
@@ -110,9 +110,9 @@ PATTERN FORMAT
and a/frotz that is a directory (all paths are relative from the .gitignore file).
- - An asterisk "*" matches string of any length, and a question mark
- "?" matches any single character, but these wildcard characters
- do not match a slash "/".
+ - An asterisk "*" matches any string (including the empty string),
+ and a question mark "?" matches any single character, but these
+ wildcard characters do not match a slash "/".
- A pair of brackets that enclose characters match one of the listed characters, and a range notation inside them, e.g., "[a-zA-Z]",
Signature · 1 line
2.56.0-511-g14903f623d