gittext-files

How to list all text (non-binary) files in a git repository?


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 to the generator tools). Additionally, the repo has a lot of source-ish files in ignored directories (again, generated as part of the build processes), and a number of actual binary files (e.g. little resource files like icons).

I'd now like to find all the non-auto-generated and non-ignored files in the repo. I thought I'd just do this with find and a bunch of exclusions, but now I have a horrendous find statement with a dozen clauses (and it still doesn't perfectly do the job). git ls-files works but shows me all the binary files without differentiation, which I have to filter out.

So, I'm wondering: is there a simple command I can run which lists every file checked into the the repo, and which git considers a "text" file?


Solution

  • git grep --cached -Il ''
    

    lists all non-empty regular (no symlinks) text files:

    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.