# How to use .gitattributes to tell git that .ini is text file?

2 messages from 2011-08-20 to 2011-08-20. Participants: jelly, Chris Packham.
Thread: https://gitlist.dev/t/28171

## jelly, 2011-08-20 02:06

Subject: How to use .gitattributes to tell git that .ini is text file?
Message-ID: <bfe44ee.e467.131e4f0b471.Coremail.sinojelly@163.com>
URL: https://gitlist.dev/e/bfe44ee.e467.131e4f0b471.Coremail.sinojelly%40163.com

```
When I use like this, it takes no effect.
C:\Users\jelly\Documents\My Knowledge\Plugins>cat .gitattributes*.ini     text
C:\Users\jelly\Documents\My Knowledge\Plugins>git diffdiff --git a/Misc/plugin.ini b/Misc/plugin.iniindex 078c8a9..f73153c 100755Binary files a/Misc/plugin.ini and b/Misc/plugin.ini differ

```

## Chris Packham, 2011-08-20 09:59

Subject: Re: How to use .gitattributes to tell git that .ini is text file?
Message-ID: <4E4F857E.9030907@gmail.com>
URL: https://gitlist.dev/e/4E4F857E.9030907%40gmail.com
In-Reply-To: <bfe44ee.e467.131e4f0b471.Coremail.sinojelly@163.com>

```
On 20/08/11 14:06, jelly wrote:
> When I use like this, it takes no effect.
> C:\Users\jelly\Documents\My Knowledge\Plugins>cat .gitattributes*.ini     text
> C:\Users\jelly\Documents\My Knowledge\Plugins>git diffdiff --git a/Misc/plugin.ini b/Misc/plugin.iniindex 078c8a9..f73153c 100755Binary files a/Misc/plugin.ini and b/Misc/plugin.ini differ

I think you might be running into some problems with the end of line
detection. What git version are you running? I think what you want in
.gitattributes is '*.ini diff' (see below)

I did some quick tests with 1.7.5 and I seem to get sane behaviour
without needing .gitattributes

  printf '\r\nfoo\r\n' > foo.ini
  git commit -m"" foo.ini

  # change content
  printf '\r\nbar\r\n' > foo.ini
  git diff
  diff --git a/foo.ini b/foo.ini
  index 35c61a9..b2b98e6 100644
  --- a/foo.ini
  +++ b/foo.ini
  @@ -1,2 +1,2 @@

  -foo
  +bar

  # insert non-printable character
  printf '\nbar\0\n' > foo.ini
  git diff
  diff --git a/foo.ini b/foo.ini
  index 35c61a9..aff5caf 100644
  Binary files a/foo.ini and b/foo.ini differ

Even with the binary content I can tell git diff to treat the files as
text (not that you can see it in the email but with less as my pager I
actually get an indication that there is a funny character there)

  git diff -a
  diff --git a/foo.ini b/foo.ini
  index 35c61a9..aff5caf 100644
  --- a/foo.ini
  +++ b/foo.ini
  @@ -1,2 +1,2 @@
  -
  -foo
  +
  +bar

If you want to tell git diff to always use the -a option for .ini files
try this

  echo '*.ini diff' > .gitattributes
  git diff
  diff --git a/foo.ini b/foo.ini
  index 35c61a9..aff5caf 100644
  --- a/foo.ini
  +++ b/foo.ini
  @@ -1,2 +1,2 @@
  -
  -foo
  +
  +bar

```
