MasterMax
MasterMax

Reputation: 11

How to remove these non existing files from Git?

MS Word did create these files automatically while the files were opened. I accidentially committed these files. After closing MS Word the files have been deleted automatically. Now Git still shows the files and I cannot remove, add or checkout them. How to remove these files from the repository?

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
  
    deleted:    NonProject/GameObjectSetupInstructions/RaceScene/~$VFX.docx
    deleted:    NonProject/GameObjectSetupInstructions/RaceScene/~$ceSceneLighting.docx
    modified:   NonProject/GameObjectSetupInstructions/RaceScene/~$ceSceneSetup.docx
        
        
        
$ git checkout NonProject/GameObjectSetupInstructions/RaceScene/~$VFX.docx
error: pathspec 'NonProject/GameObjectSetupInstructions/RaceScene/~.docx' did not match any file(s) known to git

$ git rm --cached NonProject/GameObjectSetupInstructions/RaceScene/~$VFX.docx
fatal: pathspec 'NonProject/GameObjectSetupInstructions/RaceScene/~.docx' did not match any files

$ git rm NonProject/GameObjectSetupInstructions/RaceScene/~$VFX.docx
fatal: pathspec 'NonProject/GameObjectSetupInstructions/RaceScene/~.docx' did not match any files

Upvotes: 1

Views: 136

Answers (1)

1615903
1615903

Reputation: 34732

In bash, when you use a variable in a command it is prefixed with a $. Therefore, when you type:

git rm NonProject/GameObjectSetupInstructions/RaceScene/~$VFX.docx

Bash tries to replace $VFX with a variable VFX. When it isn't found, empty string is used instead, as you can see in the error message:

fatal: pathspec 'NonProject/GameObjectSetupInstructions/RaceScene/~.docx' did not match any files

Note that $VFX has disappeared.

The solution is to quote the path with single quotes, which prevents variable substitution:

git rm 'NonProject/GameObjectSetupInstructions/RaceScene/~$VFX.docx'

Upvotes: 1

Related Questions