36

我想从 ~/bin/ 的 Git 中删除所有文件。

我跑

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

我明白了

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

此错误消息建议我使用以下 PATH,因为 ~/.vim/** 不起作用

~/.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

如何从 Git 中删除 ~/.vim 中的所有文件和子目录?

--

4

4 回答 4

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

1/你不需要' *':

 git rm -r --cached ~/.vim

将处理任何跟踪的子文件。

2/fatal: pathspec '.vim/colors' did not match any files仅表示您在 1/ 中列出的命令起作用之前尝试过的命令之一,并且没有更多文件要删除!

# 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
于 2009-06-28T13:25:25.503 回答
10

即使有本地修改,您也想删除它们?

git rm -rf bin/*

或者您想从索引中删除但保留文件本身?

git rm -r --cached bin/*

也试试:

git help rm
于 2009-06-28T02:08:22.133 回答
1

你应该先了解一下是做什么*的。

应用程序看不到*(或其他通配符)——它们接收 glob 的所有匹配项作为单独的参数。

为了更好地理解这一点,把echo你的第一个命令放在前面,看看它打印出来的内容:

 git rm -r --cached ~/.vim/*

您将看到每个单独的匹配项,包括程序不知道如何操作的内容(包括.vim/colors)。

于 2009-06-28T21:54:50.777 回答
1

或者可能是您尝试递归删除的目录位于 .gitignore 列表中。我刚遇到这个。我的忽略列表中有 ./vendors ,并且 ./vendors 下有一堆目录,但是因为 vendor 中的任何内容都被忽略了,所以它实际上并没有删除像 ./vendors/assetic 这样的东西,因为它实际上不在回购中。我忘了它在忽略列表中:)

于 2012-08-18T17:05:34.270 回答