git - 无法从 Git 中递归删除文件

标签 git rm

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

我跑

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

我明白了

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

此错误消息建议我使用以下路径,因为 ~/.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 -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

关于git - 无法从 Git 中递归删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1054044/

相关文章:

git - 跟踪 git 中子文件夹的版本号

linux - 在 linux 中删除带有反斜杠的文件

linux - 如何在 Linux 上的 Bash 中一次删除多个文件?

shell - 我不小心使用 rm *$* 删除了存储库中的文件

GitHub for Mac 每次启动时 pop "enter your password for the ssh key id_rsa"

Git merge 与在本地和源上添加的 500 个文件发生冲突

git - 试图用 git for windows 理解 wincred - 困惑

git - 将两个 git 存储库 merge 为一个,保留(重命名)master 分支

linux - Mono如何删除与正则表达式匹配的文件

bash - 在 "rm -R/*"之后做什么