Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to remove files recursively from Git

Tags:

git

rm

I want to remove all files from Git at ~/bin/.

I run

git rm -r --cached ~/.vim/*                      # Thanks to Pate in finding --cached! 

I get

fatal: pathspec '.vim/colors' did not match any files 

This error messsage suggests me to use the following PATHs, since ~/.vim/** does not work

~/.vim/*        # I get the error ~/.vim/*/*/*    # This removes files from the index at ~/.vim/folderA/folderB/file1.txt ~/.vim/*/*      # similar error as to the first PATH 

How can you remove all files and subdirectories at ~/.vim from Git?

--

like image 908
Léo Léopold Hertz 준영 Avatar asked Jun 28 '09 02:06

Léo Léopold Hertz 준영


People also ask

How do I delete a recursive file?

To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.

Will Gitignore remove files from repo?

gitignore" is very helpful, it tells me what files are excluded by . ignore. I was happy to find these commands, BUT it does not really remove the files from repository.


1 Answers

 git rm -r --cached ~/.vim/*     fatal: pathspec '.vim/colors' did not match any files 

1/ You do not need the '*':

 git rm -r --cached ~/.vim 

will take care of any tracked sub-files.

2/ fatal: pathspec '.vim/colors' did not match any files simply means one of your commands you tried before the one listed in 1/ has worked, and there is no more file to delete!

# to test that command, first reinitialize the state of the repository # save first if you have any other current modifications $ git reset --hard  # then check the rm works $ git rm -r --cached ~/.vim rm '.vim/aPath/aFile1' rm '.vim/aSecondPath/aFile2' rm '.vim/aThirdPath/aFile3'  # try it again $ git rm -r --cached ~/.vim fatal: pathspec '.vim/colors 
like image 64
VonC Avatar answered Sep 27 '22 20:09

VonC