Search code examples
gitgit-clean

git clean: What does "Would not remove" mean?


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


Solution

  • 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