edi9999 edi9999 - 3 months ago 9
Git Question

List all files that are not ignored by .gitignore

I would like to list all files that are not ignored by .gitignore, eg all source files of my repository.

ag
does it well by default, but I'm not aware of an approach that works without installing additional software.

git ls-files
without options works almost well but doesn't take into account the files that have been modified/created, for example if I create a new file bar without commiting it,
git ls-files
doesn't show that file.

Answer
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).