List all files that are not ignored by .gitignore
git status --short| grep '^?' | cut -d\ -f2-
will give you untracked files.
If you union it with git ls-files
, you've got all unignored files:
( git status --short| grep '^?' | cut -d\ -f2- && git ls-files ) | sort -u
you can then filter by
( xargs -d '\n' -- stat -c%n 2>/dev/null ||: )
to get only the files that are stat-able (== on disk).
Here is another way, using git check-ignore
which you may find it cleaner:
find . -type f
will give you all the files in the current folder.
find . -type f -not -path './.git/*'
will give you all the files, with the exception of everything in .git folder, which you definitely don't want to include. then,
for f in $(find . -type f -not -path './.git/*'); do echo $f; done
is the same as above. Just a preparation to the next step, which introduce the condition. The idea is to use the git check-ignore -q
which returns exit 0 when a path is ignored. Hence, here is the full command
for f in $(find . -type f -a -not -path './.git/*'); do
if ! $(git check-ignore -q $f); then echo $f; fi
done