清除 git 中 Untracked files

在git管理的项目下, 做一些编译或者运行测试的操作,会产生一些未追踪的文件Untracked files, 可以使用git clean命令来删除。

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   info.py

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        test/log/
        test/info.txt

no changes added to commit (use "git add" and/or "git commit -a")

$ git clean -nfd
Would remove test/log/
Would remove test/info.txt

$ git clean -fd
Removing test/log/
Removing test/info.txt
  • -f: --force, 强制删除 untracked 文件
  • -d:删除整个文件夹,-fd 强制删除 untracked 文件和文件夹
  • -n: 查看会删掉哪些文件,防止重要文件被误删
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容