How to delete Untracked files in git
Preface
Sometimes, you don't want to submit the code changes, or you want to directly pull and update the latest remote warehouse code, but the local code has already made a lot of changes. Solution:
1. Untracked files (unmonitored) files
Untracked files (unmonitored) are files you have added that have not been tracked yet. How to remove it.
1.1. Delete Untracked files
git clean -f
1.2. Delete even the untracked directory.
git clean -fd
1.3. Delete even the untracked files/directories of gitignore (use with caution, generally this is used to delete compiled .o and other files)
git clean -xfd
When you execute the above commands, these files will be deleted directly for you. It may catch you off guard, and it may make you regret it if you delete files/directories you don't want to delete.
Therefore, I suggest that before executing the above command, first execute the view command of the above command (plus -n
parameters) to see which files the command will delete.
Before using the above command, it is recommended to add -n
parameters to see which files will be deleted to prevent important files from being accidentally deleted.
git clean -nf
git clean -nfd
git clean -nxfd
Executing a command with -n
parameters will list the files that will be deleted by the command, but will not delete the files; execute the corresponding git clean
command after confirming that everything is correct.