Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git rm --cached results in fatal: pathspec

Tags:

git

I wanted to clean my repo up after adding some files to .gitignore so I ran git rm --cached * with the result:
fatal: pathspec '$Recycle.Bin' did not match any files

I assume this is due to the $ in the filename, is there a work around for this?

like image 306
ehiller Avatar asked Sep 14 '25 15:09

ehiller


2 Answers

This is just how * works. It has nothing to do with the $ at all.

$ ls
$Recycle.Bin
a
b

If I run git rm --cached *, the shell converts that to git rm --cached $Recycle.bin a b, and that's what's passed to Git.

However, $Recycle.Bin isn't part of your repository, so Git can't delete it. That's an error. Easiest way to fix this is to not use --ignore-unmatch.

$ git rm --cached --ignore-unmatch -- *
like image 183
Dietrich Epp Avatar answered Sep 16 '25 06:09

Dietrich Epp


The workaround is to replace '*' with more bounded wildcard/globs. For instance you could use something of the form mydir/{dir1,dir2}/*.{js,css}

Which should give you some idea of what you can do.

Then look at your changes to .gitignore and do a git rm --cached on each line entry, using wildcards to combine entries in case your gitignore is bloated

like image 40
bgarcia Avatar answered Sep 16 '25 06:09

bgarcia