git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: "git rm" seems to do recursive removal even without "-r"

From
Robert P. J. Day <rpjday@crashcourse.ca>
Date
Oct 11, 2017, 08:31 UTC
Message-ID
<alpine.LFD.2.21.1710110430020.10556@localhost.localdomain>
In-Reply-To
<20171010115250.GA75189@book.hvoigt.net>
On Tue, 10 Oct 2017, Heiko Voigt wrote:
Show 33 quoted lines
> On Sun, Oct 08, 2017 at 07:56:20AM -0400, Robert P. J. Day wrote:
> >   but as i asked in my earlier post, if i wanted to remove *all* files
> > with names of "Makefile*", why can't i use:
> >
> >   $ git rm 'Makefile*'
> >
> > just as i used:
> >
> >   $ git rm '*.c'
> >
> > are those not both acceptable fileglobs? why does the former
> > clearly only match the top-level Makefile, and refuse to cross
> > directory boundaries?
>
> Maybe think about it this way: The only difference between git's
> globbing and the default shell globbing is that the '/' in a path
> has a special meaning. The shells expansion stops at a '/' but git
> does not.
>
> So with *.c the shell matches: blabla.c, blub.c, ...  but not
> subdir/bla.c, subdir/blub.c, ... since it only considers files in
> the current directory. A little different for Makefile* that will
> also match Makefile.bla, Makefile/bla or Makefile_bla/blub in shell
> but not subdir/Makefile or bla.Makefile. Basically anything directly
> in *this* directory that *starts* with 'Makefile'.
>
> Git on the other hand does not consider '/' to be special. So *.c
> matches all of the path above: bla.c, blub.c, subdir/bla.c,
> subdir/blub.c. Basically any file below the current directory with a
> path that ends in '.c'. With Makefile* it is the opposite: Every
> file below the current directory that *starts* with 'Makefile'. So
> Makefile.bla, Makefile/bla, ... but also not subdir/Makefile or
> bla.Makefile.
   ok, i believe i finally appreciate what is happening here, and
perhaps my first contribution will be a minor addition to the "git-rm"
man page to introduce a couple examples explaining these intricacies,
since they're not immediately obvious. i'll put something together and
submit it to the list. thank you all for your patience in explaining
this.
rday
-- 
========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================
Previous: Heiko VoigtNext: Paul Smith
Message 20 of 29 in “"git rm" seems to do recursive removal even without "-r"”
  1. Robert P. J. DayOct 7, 2017
  2. Todd ZullingerOct 7, 2017
  3. Robert P. J. DayOct 7, 2017
  4. Jeff KingOct 7, 2017
  5. Robert P. J. DayOct 7, 2017
  6. Jeff KingOct 7, 2017
  7. Robert P. J. DayOct 7, 2017
  8. Theodore Ts'oOct 7, 2017
  9. Robert P. J. DayOct 7, 2017
  10. Paul SmithOct 7, 2017
  11. Robert P. J. DayOct 7, 2017
  12. Junio C HamanoOct 8, 2017
  13. Robert P. J. DayOct 8, 2017
  14. Kevin DaudtOct 8, 2017
  15. Robert P. J. DayOct 8, 2017
  16. Martin ÅgrenOct 8, 2017
  17. René ScharfeOct 8, 2017
  18. Robert P. J. DayOct 8, 2017
  19. Heiko VoigtOct 10, 2017
  20. Robert P. J. DayOct 11, 2017
  21. Paul SmithOct 8, 2017
  22. Theodore Ts'oOct 8, 2017
  23. Robert P. J. DayOct 8, 2017
  24. Theodore Ts'oOct 8, 2017
  25. Jeff KingOct 9, 2017
  26. Robert P. J. DayOct 10, 2017
  27. Junio C HamanoOct 10, 2017
  28. Paul SmithOct 10, 2017
  29. Robert P. J. DayOct 10, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.