git rm *不会一次删除所有文件 [英] git rm * doesn't remove all files in one go

查看:238
本文介绍了git rm *不会一次删除所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了一些git的示例说明,并遇到了这种特殊情况,当我们执行 git rm * 时,它不会删除。* 文件在第一次尝试。
为什么会这样?

I was trying out some sample instructions of git and came across this peculiar case that when we do a git rm *, it doesn't delete the .* files in the first attempt. Why is it so?

mkdir -p test_repo1/folder && cd test_repo1
touch .testfile1 .testfile2 testfile3 folder/testfile4 folder/.testfile5
git init && git add . && git commit -m "test commit"

如果现在我做一个 git rm 如下,我必须再次删除所有文件

If now I do a git rm as follows, I have to do it a second time to remove all the files

$ git rm -r *
rm 'folder/.testfile5'
rm 'folder/testfile4'
rm 'testfile3'

$ git rm -r *
rm '.testfile1'
rm '.testfile2'

为什么不把git全部删除文件在第一次尝试本身?另外,为什么这只会发生只有repo root的文件?

Why doesn't git remove all files in the first attempt itself? Also, why is this happening for files withing the repo root only?

有趣的是,如果我只有那些 .testfiles ,那么git会在第一次尝试中删除它们。

Interestingly, if all I have are those .testfiles, then git removes them in the first attempt itself.

我使用的是git版本 1.7.9.5

I am using git version 1.7.9.5

推荐答案

通配符在您的shell中得到扩展,并且默认情况下,扩展不包括点文件在大多数shell中。

The wildcard gets expanded by your shell, and the expansion does not include dot files, by default, in most shells.

因此,当 git 执行时,第一个命令已经变成

So by the time git executes, the first command has become

git rm -r folder testfile3

第二个可能是字面值

and the second probably a literal

git rm -r *

其中 git 然后自行扩展。

由于基思,一次去除所有东西,防止外壳扩大通配符,以便 git 已经第一次进行了扩展。这可以用双引号或单引号完成,或者在星号前加反斜杠。我倾向于使用单引号:

As remarked by Keith, to remove everything in one go, prevent the shell from expanding the wildcard so that git does the expansion the first time already. This can be done with double or single quotes, or with a backslash before the asterisk. I tend to prefer single quotes:

git rm -r '*'

这篇关于git rm *不会一次删除所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆