"git clean
"(man) and git ls-files -i
(man) had confusion around working on or showing ignored paths inside an ignored directory, which has been corrected with Git 2.32 (Q2 2021).
That means the 2021 version of the accepted answer would be:
git ls-files -i -c --exclude-from=.gitignore | xargs git rm --cached
^^
See commit b548f0f, commit dd55fc0, commit aa6e1b2, commit a97c7a8, commit 2e4e43a, commit b338e9f, commit 7fe1ffd, commit 7f9dd87 (12 May 2021) by Elijah Newren (newren
).
See commit 4e689d8 (12 May 2021) by Derrick Stolee (derrickstolee
).
(Merged by Junio C Hamano -- gitster
-- in commit 33be431, 20 May 2021)
ls-files
: error out on -i unless -o or -c are specified
Signed-off-by: Elijah Newren
ls-files --ignored
(man) can be used together with either --others
or --cached
.
After being perplexed for a bit and digging in to the code, I assumed that ls-files -i
was just broken and not printing anything and I had a nice patch ready to submit when I finally realized that -i
can be used with --cached
to find tracked ignores.
While that was a mistake on my part, and a careful reading of the documentation could have made this more clear, I suspect this is an error others are likely to make as well.
In fact, of two uses in our testsuite, I believe one of the two did make this error.
In t1306.13, there are NO tracked files, and all the excludes built up and used in that test and in previous tests thus have to be about untracked files.
However, since they were looking for an empty result, the mistake went unnoticed as their erroneous command also just happened to give an empty answer.
-i
will most the time be used with -o
, which would suggest we could just make -i
imply -o
in the absence of either a -o
or -c
, but that would be a backward incompatible break.
Instead, let's just flag -i
without either a -o
or -c
as an error, and update the two relevant testcases to specify their intent.
That means without -c
, you would get (starting with Git 2.32, Q2 2021):
fatal: ls-files -i must be used with either -o or -c
Note: this is still a work in progress, since it was reverted in Git 2.32-rc2 but fixed with commit 2c9f1bf, commit 1df046b (27 May 2021) by Junio C Hamano (gitster
).
See commit 906fc55 (27 May 2021) by Elijah Newren (newren
).
See commit eef8148 (27 May 2021) by Derrick Stolee (derrickstolee
).
(Merged by Junio C Hamano -- gitster
-- in commit 329d63e, 28 May 2021)
dir
: introduce readdir_skip_dot_and_dotdot()
helper
Signed-off-by: Elijah Newren