git clean without ignored files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I noticed that `git clean` does not handle a specific scenario. I have
the following types of untracked entities in my working copy:

* Untracked files in tracked directories (non-recursive; sibling files
are tracked)
* Untracked files in untracked directories (recursive)
* Ignored files meeting the same criteria above

My goal is to clean the first 2 points, but not the 3rd. Basically, I
want all untracked files that show up in `git status` to be removed,
but not ignored files or directories.

If I run this command:

$ git clean -nd

I get a list of all the untracked files but oddly I get a few
directories in the list that indirectly ignored via my .gitignore.
Basically, the directory itself isn't ignored by any pattern in my
.gitignore but its entire contents (recursively) is ignored, due to
patterns matching the files themselves.

I think `clean` sees this as an untracked directory, because it's not
specifically matching a pattern in my .gitignore. Whereas git status
is smart enough to not display it because it knows that every single
file contained in there, regardless of depth, matches an ignore
pattern.

As a workaround, the following command accomplishes what I want:

$ git ls-files --others --exclude-standard | sed 's/.*/"&"/' | xargs rm -rfv

Is there a reason why `git clean -nd` file listing doesn't match more
closely with what I see in `git status` regarding untracked files and
directories?

Note I am aware git does not directly track directories. So when I
refer to tracked/untracked directories, I'm actually referring to that
directories contents recursively. If recursively 100 files exist, but
only 99 are ignored, then I consider that root directory to be
"untracked" but not ignored, because 1 file still shows up in `git
status`.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]