无法从Git中递归删除文件

无法从Git中递归删除文件,git,rm,Git,Rm,我想从Git中删除位于~/bin/的所有文件 我跑 我明白了 此错误消息建议我使用以下路径,因为~/.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中删除位于~

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

我跑

我明白了

此错误消息建议我使用以下路径,因为~/.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的所有文件和子目录?


--

即使有本地修改,也要删除它们吗

git rm -rf bin/*
还是要从索引中删除,但保留文件本身

git rm -r --cached bin/*
还可以尝试:

git help rm
1/您不需要“
*
”:

 git rm -r --cached ~/.vim
将处理所有跟踪的子文件

2/
fatal:pathspec'.vim/colors'与任何文件都不匹配
仅表示您在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

您应该先了解一下
*
的作用

应用程序看不到
*
(或其他全局字符)--它们将全局的所有匹配项作为单个参数接收

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

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

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

或者您尝试递归删除的目录可能在.gitignore列表中。我刚刚遇到了这个。我的忽略列表中有./vendors,在./vendors下有一堆目录,但由于忽略了vendors中的任何内容,因此实际上不会删除像./vendors/assetic这样的内容,因为它实际上不在回购协议中。我忘了它在“忽略列表”中:

@ PAT:我想从Git中删除文件,这样我就可以在我的机器中删除文件了。这个答案是被改变的问题的基础。@冯:谢谢你的帮助!这是否也会从git中删除早期版本中这些文件的任何历史痕迹?@CraigHicks No,不会。为此,您需要git filter branch()或BFG:我觉得这个答案应该包括所描述的echo,以及OP实际问题的解决方案。
 git rm -r --cached ~/.vim
# 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
 git rm -r --cached ~/.vim/*