* Unexpected recursion in 'git rm'
@ 2026-07-02 7:49 Евгений Плискин
2026-07-03 7:01 ` Matt Hunter
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Евгений Плискин @ 2026-07-02 7:49 UTC (permalink / raw)
To: git
Hello.
The following git command does recurse directories as contrary to the reference (https://git-scm.com/docs/git-rm):
git rm -n *.json
Without directory specification before '*.json' this command is not expected to recurse directories, but it really does.
git version 2.55.0.windows.1
--
Regards,
Eugene Pliskin mailto:eugene.pliskin@gmail.com
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: Unexpected recursion in 'git rm'
2026-07-02 7:49 Unexpected recursion in 'git rm' Евгений Плискин
@ 2026-07-03 7:01 ` Matt Hunter
[not found] ` <1978773121.20260703123754@gmail.com>
2026-07-03 8:31 ` Patrick Steinhardt
2026-07-03 15:25 ` Mikael Magnusson
2 siblings, 1 reply; 8+ messages in thread
From: Matt Hunter @ 2026-07-03 7:01 UTC (permalink / raw)
To: Евгений Плискин,
git
On Thu Jul 2, 2026 at 3:49 AM EDT, Евгений Плискин wrote:
> Hello.
>
> The following git command does recurse directories as contrary to the reference (https://git-scm.com/docs/git-rm):
>
> git rm -n *.json
>
> Without directory specification before '*.json' this command is not expected to recurse directories, but it really does.
>
> git version 2.55.0.windows.1
Hi - I threw a quick test repo together, but did not see the result you
describe. Could you produce a script or series of commands to reproduce
the problem?
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: Unexpected recursion in 'git rm'
2026-07-02 7:49 Unexpected recursion in 'git rm' Евгений Плискин
2026-07-03 7:01 ` Matt Hunter
@ 2026-07-03 8:31 ` Patrick Steinhardt
2026-07-03 10:04 ` Phillip Wood
[not found] ` <1756071445.20260703123414@gmail.com>
2026-07-03 15:25 ` Mikael Magnusson
2 siblings, 2 replies; 8+ messages in thread
From: Patrick Steinhardt @ 2026-07-03 8:31 UTC (permalink / raw)
To: Евгений Плискин
Cc: git
Hi,
On Thu, Jul 02, 2026 at 10:49:10AM +0300, Евгений Плискин wrote:
> Hello.
>
> The following git command does recurse directories as contrary to the
> reference (https://git-scm.com/docs/git-rm):
>
> git rm -n *.json
>
> Without directory specification before '*.json' this command is not
> expected to recurse directories, but it really does.
This is expected behaviour, as the argument to git-rm(1) is a pathspec,
and "*" matches directory separators by default, see also gitglossary(7)
under "pathspec":
• the pathspec up to the last slash represents a directory prefix. The
scope of that pathspec is limited to that subtree.
• the rest of the pathspec is a pattern for the remainder of the
pathname. Paths relative to the directory prefix will be matched
against that pattern using fnmatch(3); in particular, * and ? can
match directory separators.
For example, Documentation/*.jpg will match all .jpg files in the
Documentation subtree, including Documentation/chapter_1/figure_1.jpg.
Could you maybe clarify which part of git-rm(1) made you think that this
wouldn't happen?
Thanks!
Patrick
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: Unexpected recursion in 'git rm'
2026-07-03 8:31 ` Patrick Steinhardt
@ 2026-07-03 10:04 ` Phillip Wood
[not found] ` <1756071445.20260703123414@gmail.com>
1 sibling, 0 replies; 8+ messages in thread
From: Phillip Wood @ 2026-07-03 10:04 UTC (permalink / raw)
To: Patrick Steinhardt,
Евгений Плискин
Cc: git
On 03/07/2026 09:31, Patrick Steinhardt wrote:
> On Thu, Jul 02, 2026 at 10:49:10AM +0300, Евгений Плискин wrote:
>> Hello.
>>
>> The following git command does recurse directories as contrary to the
>> reference (https://git-scm.com/docs/git-rm):
>>
>> git rm -n *.json
>>
>> Without directory specification before '*.json' this command is not
>> expected to recurse directories, but it really does.
Are there any ".json" files in the directory where you're running this?
As the glob is not quoted, I think maybe what is happening is that there
are no matching files in the current directory so the shell is not
expanding the glob as you expect and is passing it to git which treats
it as Patrick explains below.
Thanks
Phillip
> This is expected behaviour, as the argument to git-rm(1) is a pathspec,
> and "*" matches directory separators by default, see also gitglossary(7)
> under "pathspec":
>
> • the pathspec up to the last slash represents a directory prefix. The
> scope of that pathspec is limited to that subtree.
>
> • the rest of the pathspec is a pattern for the remainder of the
> pathname. Paths relative to the directory prefix will be matched
> against that pattern using fnmatch(3); in particular, * and ? can
> match directory separators.
>
> For example, Documentation/*.jpg will match all .jpg files in the
> Documentation subtree, including Documentation/chapter_1/figure_1.jpg.
>
> Could you maybe clarify which part of git-rm(1) made you think that this
> wouldn't happen?
>
> Thanks!
>
> Patrick
>
^ permalink raw reply [flat|nested] 8+ messages in thread[parent not found: <1756071445.20260703123414@gmail.com>]
* Re: Unexpected recursion in 'git rm'
[not found] ` <1756071445.20260703123414@gmail.com>
@ 2026-07-03 12:39 ` Patrick Steinhardt
0 siblings, 0 replies; 8+ messages in thread
From: Patrick Steinhardt @ 2026-07-03 12:39 UTC (permalink / raw)
To: Евгений Плискин
Cc: git
Adding the mailing list back into Cc.
On Fri, Jul 03, 2026 at 12:34:14PM +0300, Евгений Плискин wrote:
> > This is expected behaviour, as the argument to git-rm(1) is a pathspec, and "*" matches directory separators by default, see also gitglossary(7) under "pathspec":
> > • the pathspec up to the last slash represents a directory prefix. The scope of that pathspec is limited to that subtree.
> > • the rest of the pathspec is a pattern for the remainder of the pathname. Paths relative to the directory prefix will be matched against that pattern using fnmatch(3); in particular, * and ? can match directory separators.
> > For example, Documentation/*.jpg will match all .jpg files in the Documentation subtree, including Documentation/chapter_1/figure_1.jpg.
> > Could you maybe clarify which part of git-rm(1) made you think that this wouldn't happen?
>
> Thank you for your reply. I believe you are correct.
>
> I have made more research and found a way to remove files in current directory only without recursion into subdirectories:
> git rm -n ':(glob)*.json'
Yup, that wouldn't cross directory separators indeed.
Patrick
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Unexpected recursion in 'git rm'
2026-07-02 7:49 Unexpected recursion in 'git rm' Евгений Плискин
2026-07-03 7:01 ` Matt Hunter
2026-07-03 8:31 ` Patrick Steinhardt
@ 2026-07-03 15:25 ` Mikael Magnusson
2026-07-03 20:41 ` Junio C Hamano
2 siblings, 1 reply; 8+ messages in thread
From: Mikael Magnusson @ 2026-07-03 15:25 UTC (permalink / raw)
To: Евгений Плискин
Cc: git
On Thu, Jul 2, 2026 at 9:51 AM Евгений Плискин <eugene.pliskin@gmail.com> wrote:
>
> Hello.
>
> The following git command does recurse directories as contrary to the reference (https://git-scm.com/docs/git-rm):
>
> git rm -n *.json
>
> Without directory specification before '*.json' this command is not expected to recurse directories, but it really does.
>
> git version 2.55.0.windows.1
I can't see any formulation in the manpage reference that suggests it
wouldn't recurse, though you might overall get less surprised if you
set the failglob option in bash. Then the shell would notice *.json
has no matches, and you'd have to say git rm -n '*.json' to let git
process the glob instead of the shell. See also
https://git-scm.com/docs/gitglossary (as referenced from the git-rm
page) which says:
the rest of the pathspec is a pattern for the remainder of the pathname.
Paths relative to the directory prefix will be matched against that
pattern using fnmatch(3); in particular, * and ? can match directory
separators.
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-07-03 20:41 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-02 7:49 Unexpected recursion in 'git rm' Евгений Плискин
2026-07-03 7:01 ` Matt Hunter
[not found] ` <1978773121.20260703123754@gmail.com>
2026-07-03 13:04 ` Matt Hunter
2026-07-03 8:31 ` Patrick Steinhardt
2026-07-03 10:04 ` Phillip Wood
[not found] ` <1756071445.20260703123414@gmail.com>
2026-07-03 12:39 ` Patrick Steinhardt
2026-07-03 15:25 ` Mikael Magnusson
2026-07-03 20:41 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox