1

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 
3
  • 1
    Try git add 'NonProject/GameObjectSetupInstructions/RaceScene/~$VFX.docx'? Commented Jan 10, 2022 at 10:36
  • That worked! I always tried to use "" instead of ''. I thought it's equivalent... Anyway thank you so much. Commented Jan 10, 2022 at 10:55
  • 2
    @MasterMax the tilde ~ was likely being interpreted as your home directory. Try cd ~ or cd ~/Documents. Commented Jan 10, 2022 at 11:24

1 Answer 1

1

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' 
Sign up to request clarification or add additional context in comments.

3 Comments

Doesn't the replacement happen when using double-quotes too?
@evolutionxbox: for bash, yes. Different shells have different rules, so it can get messy, but that's why the single quotes worked.
I tried double quotes first and it did not work in my Git shell. Single quotes worked.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.