Search code examples
rubygitgit-rm

Git: cannot run git 'rm -rf . --cached'


I'm working with Rubygems, and it's caching files in git a lot. The easy solution is just to run git rm -rf . --cached, but when I run it, this message appears:

fatal: pathspec '' did not match any files

Even if I run git rm -rf ./\* --cached, it still returns:

fatal: pathspec '*' did not match any files

Any solutions?


Solution

  • The correct syntax would be:

    git rm -r -f --cached -- .
    

    (ie the path should be at the end)

    But if git status mentions that no files have been added, then nothing 'cached' would be there to be removed.

    When --cached is given, the staged content has to match:

    • either the tip of the branch
    • or the file on disk,

    allowing the file to be removed from just the index.