# what file extensions must be explicitly configured with respect to eol-type in gitattributes?

2 messages from 2010-09-20 to 2010-09-20. Participants: Robert Buck, Erik Faye-Lund.
Thread: https://gitlist.dev/t/25167

## Robert Buck, 2010-09-20 16:19

Subject: what file extensions must be explicitly configured with respect to eol-type in gitattributes?
Message-ID: <AANLkTikK2oL3sUYHdqoQ7C47nd6Pi53N17GSfh8nx6Q-@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikK2oL3sUYHdqoQ7C47nd6Pi53N17GSfh8nx6Q-%40mail.gmail.com

```
Hello,

One project we have in house has approximately 160 different file
extensions used for the files checked in. In our repository there are
files that MUST be CRLF (.bat, .cmd, .vcproj, etc), files that MUST be
LF (.xml, .xsl, .sh, etc), and files that MUST be binary. All others
are just text and so long as they appear in native form I'd be happy.

It would seem a default rule to handle text files would make sense:

* text=auto

But I have not found material explaining how git identifies binary
files, so one concern would be that it could mangle binary file types
in some cases.

Do I have to explicitly mention all 160 file types in the gitattributes file?

How does git internally determine whether a file is text vs binary?
Does it use the 'file' command in Unix?

And where I am going with this specifically is a question: what rules
MUST be specifically stated in gitattributes and what rules are there
implicitly?

Thank you,

Bob

```

## Erik Faye-Lund, 2010-09-20 16:51

Subject: Re: what file extensions must be explicitly configured with respect to eol-type in gitattributes?
Message-ID: <AANLkTikJO631YDE_UpNrC-4kjc_LF5_Gb8Xv7pCJfOf=@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikJO631YDE_UpNrC-4kjc_LF5_Gb8Xv7pCJfOf%3D%40mail.gmail.com
In-Reply-To: <AANLkTikK2oL3sUYHdqoQ7C47nd6Pi53N17GSfh8nx6Q-@mail.gmail.com>

```
On Mon, Sep 20, 2010 at 6:19 PM, Robert Buck <buck.robert.j@gmail.com> wrote:
> Hello,
>
> One project we have in house has approximately 160 different file
> extensions used for the files checked in. In our repository there are
> files that MUST be CRLF (.bat, .cmd, .vcproj, etc), files that MUST be
> LF (.xml, .xsl, .sh, etc), and files that MUST be binary. All others
> are just text and so long as they appear in native form I'd be happy.
>
> It would seem a default rule to handle text files would make sense:
>
> * text=auto
>
> But I have not found material explaining how git identifies binary
> files, so one concern would be that it could mangle binary file types
> in some cases.
>
> Do I have to explicitly mention all 160 file types in the gitattributes file?

If you want to be 100% sure, yes.

> How does git internally determine whether a file is text vs binary?
> Does it use the 'file' command in Unix?

No. Git applies the following heuristics to the file content:
- Does the file contain any NUL-characters? If so, it's binary.
- Is the ratio of printable characters vs non-printable characters
(when interpreted as ascii) below 128? If so, it's binary.
- Otherwise, it's text.

You can find the exact function here (beware of wrapping):
http://git.kernel.org/?p=git/git.git;a=blob;f=convert.c;h=01de9a84c21b31a0120065a32a386f27321cdf7b;hb=HEAD#l77

In general, this works pretty well. In addition, there's the
core.safecrlf configuration variable, which can be used to protect you
against normalizing the file in such a way that the exact original
file can't be recovered.

> And where I am going with this specifically is a question: what rules
> MUST be specifically stated in gitattributes and what rules are there
> implicitly?

Given the above information, you should be able to figure this one out
for yourself. The answer depends on how pedantic you are ;)

```
