I have a repository with a lot of autogenerated source files I\'ve marked as \"binary\" in .gitattributes
(they are checked in because not everyone has access t
git grep --cached -Il ''
lists all non-empty regular (no symlinks) text files:
-I
: don't match the pattern in binary files-l
: only show the matching file names, not matching lines''
: the empty string makes git grep
match any non-empty file--cached
: also find files added with git add
but not yet committed (optional)Or you could use How to determine if Git handles a file as binary or as text? in a for loop with git ls-files
.
TODO empty files.
Find all binary files instead: Find all binary files in git HEAD
Tested on Git 2.16.1 with this test repo.
The standard method for listing non-ignored files is:
git ls-files --exclude-standard --cached
But, as you seen, it lists all versioned files.
One workaround could be to define in a separate file "exclude_binaries
" an exclusion pattern in order to match all binaries that you know of.
git ls-files --exclude-standard --cached \
--exclude-from=/path/to/`exclude_binaries`
That would be a less complex find
, but it doesn't provide a fully automated way to list non-binary files: you still have to identify and list them in a separate pattern file.
A clever hack to achieve this: listing all non-binary files that contains carriage returns
$ git grep --cached -I -l -e $'\r'
For my case, an empty string works better:
$ git grep --cached -I -l -e $''
Took it from git list binary and/or non-binary files?.