Show all ignored files in git
My Kung-Fu to list all ignored files recursively with rules
find . -type d | grep -v .git | awk '{print $1"/"}' | git check-ignore -v --stdin
Having find
(likely on UNIX/Linux), you can issue the following command in the root folder of your git repository:
find . -type f | git check-ignore --stdin
find . -type f
will list all files in the folder recursively, while git check-ignore
will list those files from the list, which are effectively ignored by .gitignore
.
The check-ignore
command is relatively new. If your .git
version does not support it already, you can use the following workaround with a POSIX compatible shell (like bash, sh, dash, zsh). It is based on the fact that .gitignore
contains glob patterns which are meant to be interpreted by a shell. The workaround iterates over the glob patterns from .gitignore
, expands them in the shell and filters out directories from it:
while read glob ; do
if [ -d "$glob" ] ; then
# Be aware of the fact that even out of an ignored
# folder a file could have been added using git add -f
find "$glob" -type f -exec \
bash -c "FILE={};[ \$(git status -s \$FILE) == "" ] && echo \$FILE" \;
else
for file in "$glob" ; do
# Again, be aware of files which add been added using -f
bash -c "FILE={};[ \$(git status -s \$FILE) == "" ] && echo \$FILE" \;
done
fi
# Pipe stderr to /dev/null since .gitignore might contain entries for non
# existing files which would trigger an error message when passing them to find
done < .gitignore 2>/dev/null | sort