Re: Unexpected recursion in 'git rm'
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Jul 3, 2026, 10:04 UTC
- Message-ID
- <5827a94f-0f13-4747-8257-b67fb9d79ecd@gmail.com>
- In-Reply-To
- <akdzSHrJ4DfdUWoS@pks.im>
On 03/07/2026 09:31, Patrick Steinhardt wrote:
Show 10 quoted lines
> 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
Show 22 quoted lines
> 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 >