git rm*不会一次删除所有文件

mu *_*u 無 7 git

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

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"
Run Code Online (Sandbox Code Playgroud)

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

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

$ git rm -r *
rm '.testfile1'
rm '.testfile2'
Run Code Online (Sandbox Code Playgroud)

为什么git在第一次尝试中没有删除所有文件?另外,为什么仅对具有repo root的文件发生这种情况?

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

我正在使用git版本 1.7.9.5

tri*_*eee 23

通配符由shell扩展,默认情况下,扩展在大多数shell中不包括点文件.

所以到时候git执行,第一个命令就变成了

git rm -r folder testfile3
Run Code Online (Sandbox Code Playgroud)

第二个可能是文字

git rm -r *
Run Code Online (Sandbox Code Playgroud)

git然后通过自身扩张.

正如Keith所说,要一次性删除所有内容,请阻止shell扩展通配符,以便git第一次进行扩展.这可以使用双引号或单引号,或者在星号前使用反斜杠来完成.我倾向于选择单引号:

git rm -r '*'
Run Code Online (Sandbox Code Playgroud)


Tod*_*obs 5

壳牌全球化

当你运行git rm *时,实际上是使用shell的globbing规则将参数传递给git-rm(1).默认情况下,许多shell不包含隐藏文件(例如带有前导点的文件).在Bash中,您可以使用dotglobGLOBIGNORE更改globbing规则.例如: