Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 932
nonot1 Avatar asked Dec 26 '11 19:12

nonot1


People also ask

What does git clean does?

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 .

Does git clean remove ignored files?

The git clean command also allows removing ignored files and directories.

Does git clean delete files from computer?

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.

Does git checkout remove untracked files?

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).


1 Answers

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

like image 103
Lily Ballard Avatar answered Oct 15 '22 00:10

Lily Ballard