如果我的存储库中有一个目录 app,其中有一个未跟踪的文件,并且我执行 git clean -f
,我会收到消息:不删除应用程序/,未跟踪的文件仍然存在。
但是如果我在同一目录中有一个额外的跟踪文件,并且我执行完全相同的命令,那么未跟踪文件将被成功删除。
所以我的问题是:如果从未跟踪的文件中清除目录后该目录为空,为什么 Git 会尝试删除该目录?
下面是一个重现该行为的脚本。提前致谢。
#!/bin/bash
# Create new empty repo
mkdir myrepo && cd myrepo
git init
# Create app directory with main.c
mkdir app
touch app/main.c
# Try to delete main.c with git clean -> Not working
git clean -f
# Add helper.c to app directory and add to index
touch app/helper.c
git add app/helper.c
# Try to delete main.c with git clean -> Now it's working
git clean -f
最佳答案
您需要为 git clean
传递 -d
选项以删除未跟踪的目录。
关于git - "git clean -f"不留下空目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18560505/