git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Chris Packham <judge.packham@gmail.com>
Date
Aug 20, 2011, 09:59 UTC
Message-ID
<4E4F857E.9030907@gmail.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
Previous: jelly
Message 2 of 2 in “How to use .gitattributes to tell git that .ini is text file?”
  1. jellyAug 20, 2011
  2. Chris PackhamAug 20, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.