Re: "git rm" seems to do recursive removal even without "-r"
- From
Heiko Voigt <hvoigt@hvoigt.net>
- Date
- Oct 10, 2017, 11:52 UTC
- Message-ID
- <20171010115250.GA75189@book.hvoigt.net>
- In-Reply-To
- <alpine.LFD.2.21.1710080736530.21897@localhost.localdomain>
On Sun, Oct 08, 2017 at 07:56:20AM -0400, Robert P. J. Day wrote:
Show 12 quoted lines
> 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.
Maybe that helps...
Cheers Heiko