When I run git clean --dry-run
the results are a bit like:
Would remove an_untracked_file Would remove an_untracked_file_2 Would not remove some_unrelated_folder/subfolder/
The "unrelated" folders are tracked and have had no changes, so I would not expect git to remove them.
But, why does git report Would not remove
for some, but not all, of my project's normal (and totally untouched) folders?
Can I tell what is causing git to consider, but then decide against, removing them?
git status
lists only the couple of un-tracked files I know about. As expected.
git ls-files --other --exclude-standard
returns those same un-tracked files. As expected.
git ls-files --other --exclude-standard --directory
returns those same un-tracked files, plus a bunch of seemingly normal directories. This is not what I expected to see since I thought the purpose of --directory
was to reduce, not increase the number of results returned.
Upon spot checking the unexpected directories, it seems each one is empty, except for a ".gitignore"d .svn sub-folder. Perhaps this factors in to things.
Can anyone help me understand this behavior?
Thank you
Summary. To recap, git clean is a convenience method for deleting untracked files in a repo's working directory. Untracked files are those that are in the repo's directory but have not yet been added to the repo's index with git add .
The git clean command also allows removing ignored files and directories.
git clean removes untracked files from the working directory. It does not remove files that have been committed. To do that you would use git rm . So if your git repo is at the root of your hard drive, then running git clean -df would remove all the files from your disk that aren't committed.
git checkout does not affect untracked files. Git only manages tracked files, and it works fairly hard to avoid letting you lose data (which is critical).
By default, git clean
doesn't remove folders. It's telling you that it sees an untracked folder, but it won't remove it. Give it the -d
flag to instruct it to remove directories as well, as in git clean -d -n
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With