threads / discuss / 28171

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

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

## tl;dr

2 messages between Aug 20, 2011 and Aug 20, 2011.

replies: 1people: 2as markdown or json

jelly· Aug 20, 2011, 02:06 UTC · lore

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· Aug 20, 2011, 09:59 UTC · re: jelly · lore

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

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

← back to recent threads