delete untracked files with git clean
git clean -nxdf git checkout . && git clean -xdf
How to Use Git Clean
Git clean is a command that allows you to delete untracked files from your working directory. To use Git clean, you need to open your terminal and navigate to the root directory of your repository. Once you are in the root directory, you can run the following command to delete all untracked files:
git clean -f
This command will delete all untracked files from your working directory. If you want to preview the files that will be deleted before running the command, you can use the dry-run flag:
git clean -n
This command will show you a list of the files that will be deleted, but it will not actually delete them. Once you have reviewed the list of files, you can run the original command to delete them.
Using Git Clean with Options
Git clean also provides additional options that you can use to specify which types of files to delete. For example, if you only want to delete untracked files that are ignored by Git, you can use the following command:
git clean -fX
-X flag tells Git to only delete ignored files. If you want to delete both untracked files and directories, you can use the
git clean -fd
This command will delete all untracked files and directories.
In conclusion, Git clean is a powerful command that allows you to delete untracked files from your working directory. By default, Git clean will delete all untracked files, but you can use options to specify which types of files to delete. As with all Git commands, it is important to use Git clean with caution to avoid accidentally deleting important files.
## dryrun 检查哪些文件待删除 git clean -n ## 删除当前目录下没有被track过的文件和目录 git clean -df ## 删除当前目录下所有没有track过的文件，包含.gitignore文件里面的文件和目录 git clean -xf
Small world. Big idea!
- Welcome to visit the knowledge base of SRE and DevOps!
- License under CC BY-NC 4.0
- No personal information is collected
- Made with Material for MkDocs and generative AI tools
- Copyright issue feedback me#imzye.com, replace # with @
- Get latest SRE news and discuss on Discord Channel