threads / discuss / 20724

git list binary and/or non-binary files?

Subject: git list binary and/or non-binary files?

## tl;dr

3 messages between Aug 24, 2009 and Aug 24, 2009.

replies: 2people: 2as markdown or json

skillzero@gmail.com· Aug 24, 2009, 21:50 UTC · lore

Is there a way to list the files git considers binary in a repository (and alternatively, the ones it considers text)? I have a large repository and I want to fix line endings for text files that were accidentally checked in using CRLF and can't just use the file extension alone because some files with the same extension may be binary and others not (e.g. UTF-8 .strings file is text, but a UTF-16 .strings file is binary...git already figured out based on the content that one is binary).

I thought maybe git ls-files, but I didn't see anything in there I can use for binary vs text.

Johan Herland· Aug 24, 2009, 22:14 UTC · re: skillzero@gmail.com · lore

Re: git list binary and/or non-binary files?

On Monday 24 August 2009, skillzero@gmail.com wrote:
Show 11 quoted lines
> Is there a way to list the files git considers binary in a repository
> (and alternatively, the ones it considers text)? I have a large
> repository and I want to fix line endings for text files that were
> accidentally checked in using CRLF and can't just use the file
> extension alone because some files with the same extension may be
> binary and others not (e.g. UTF-8 .strings file is text, but a UTF-16
> .strings file is binary...git already figured out based on the content
> that one is binary).
>
> I thought maybe git ls-files, but I didn't see anything in there I can
> use for binary vs text.

I use the following to list files that contain CRs, but that are not considered binary by Git:

  git grep --cached -I -l -e $'\r'
'git help grep' explains all the options...
Have fun! :)
...Johan
-- 
Johan Herland, <johan@herland.net>
www.herland.net
skillzero@gmail.com· Aug 24, 2009, 22:39 UTC · re: Johan Herland · lore

Re: git list binary and/or non-binary files?

On Mon, Aug 24, 2009 at 3:14 PM, Johan Herland<johan@herland.net> wrote:
> I use the following to list files that contain CRs, but that are not
> considered binary by Git:
>
>  git grep --cached -I -l -e $'\r'

Thanks, that's what I needed. I needed it to build a list to pass to a script so I used 'git grep -I --name-only -z -e "" | xargs -o ...'

← back to recent threads