mkdir repo
cd repo
git init
mkdir temp
touch temp/in.tmp
touch out.tmp
echo '*tmp' > .gitignore
Run Code Online (Sandbox Code Playgroud)
使用git clean -Xn时显示Would remove out.tmp
但我想删除temp/in.tmp在一起
git clean -Xdn不起作用,但cd对temp目录和运行git clean -Xn它显示Would remove in.tmp
所以我想知道是否有一个命令删除.gitignoreinclude子目录中的所有文件列表,在这种情况下如何使用git cleanremove temp/in.tmp和out.tmp
$ git --version
git version 1.9.5.msysgit.1
Run Code Online (Sandbox Code Playgroud)
我发现了一些奇怪的东西
在temp目录中添加一个文件并暂存它,git clean -Xn似乎工作
touch temp/a.txt
git add temp/a.txt
git clean -Xn
Run Code Online (Sandbox Code Playgroud)
它表明
Would remove out.tmp
Would remove temp/in.tmp
Run Code Online (Sandbox Code Playgroud)
但为什么会这样呢?
需要,-x因为您要删除被忽略的文件.gitignore
git clean -fdx
将成功为您清理一切
macsp:repo proto$ git clean -fdxn
Would remove .gitignore
Would remove out.tmp
Would remove temp/
macsp:repo proto$