{"thread":{"id":"41340","subject":"git clean without ignored files","startedAt":"2016-02-05T15:42:10Z","lastAt":"2016-02-05T15:42:10Z","messageCount":1,"participants":["Robert Dailey"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"277544","messageId":"CAHd499Dhz-2+z_E8muPaucjfMhbcJisVM2eyQf=U4DOvgv2oZg@mail.gmail.com","threadId":"41340","inReplyTo":null,"subject":"git clean without ignored files","fromName":"Robert Dailey","fromEmail":"rcdailey.lists@gmail.com","sentAt":"2016-02-05T15:42:10Z","receivedAt":"2016-02-05T15:42:10Z","isPatch":false,"sender":{"key":"rcdailey.lists@gmail.com","avatar":null},"body":"I noticed that `git clean` does not handle a specific scenario. I have\nthe following types of untracked entities in my working copy:\n\n* Untracked files in tracked directories (non-recursive; sibling files\nare tracked)\n* Untracked files in untracked directories (recursive)\n* Ignored files meeting the same criteria above\n\nMy goal is to clean the first 2 points, but not the 3rd. Basically, I\nwant all untracked files that show up in `git status` to be removed,\nbut not ignored files or directories.\n\nIf I run this command:\n\n$ git clean -nd\n\nI get a list of all the untracked files but oddly I get a few\ndirectories in the list that indirectly ignored via my .gitignore.\nBasically, the directory itself isn't ignored by any pattern in my\n.gitignore but its entire contents (recursively) is ignored, due to\npatterns matching the files themselves.\n\nI think `clean` sees this as an untracked directory, because it's not\nspecifically matching a pattern in my .gitignore. Whereas git status\nis smart enough to not display it because it knows that every single\nfile contained in there, regardless of depth, matches an ignore\npattern.\n\nAs a workaround, the following command accomplishes what I want:\n\n$ git ls-files --others --exclude-standard | sed 's/.*/\"&\"/' | xargs rm -rfv\n\nIs there a reason why `git clean -nd` file listing doesn't match more\nclosely with what I see in `git status` regarding untracked files and\ndirectories?\n\nNote I am aware git does not directly track directories. So when I\nrefer to tracked/untracked directories, I'm actually referring to that\ndirectories contents recursively. If recursively 100 files exist, but\nonly 99 are ignored, then I consider that root directory to be\n\"untracked\" but not ignored, because 1 file still shows up in `git\nstatus`.\n"}]}