我希望清理被.gitignore忽略的文件,但是我想要排除一些由排除选项指定的文件。
然后,我不想删除未跟踪的文件。
dist (ignored)
node_modules (ignored)
.env (ignored but I want to exclude for the cleanup)
I_do_not_want_add_yet.js (untracked, I don't want cleanup some untracked files)
package.json (There are many other tracked files)
所以我查看了一些帖子并尝试了以下命令:
$ git clean -ndX -e .env
Would remove dist/
Would remove node_modules/
Would remove .env # Oops!
$ git clean -ndX --exclude='!.env'
Would remove dist/
Would remove node_modules/
Would remove .env # Oops!
$ git clean -ndx -e .env
Would remove dist/
Would remove node_modules/
Would remove I_do_not_want_add_yet.js # Oops!
你有好的想法吗?
git status --ignored
命令,然后在删除文件之前从中筛选出要保留的文件。 - millimoose