8

This is pretty unintuitive:

C:\python-tdl\examples\termbox>git config core.autocrlf
false

C:\python-tdl\examples\termbox>git commit termbox.py
warning: LF will be replaced by CRLF in examples/termbox/termbox.py.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in examples/termbox/termbox.py.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in examples/termbox/termbox.py.
The file will have its original line endings in your working directory.
Aborting commit due to empty commit message.

According to various media with core.autocrlf=false there should be no linefeed conversion at all.

In project root I discovered .gitattributes with the line:

# Auto detect text files and perform LF normalization
* text=auto

If I comment it, the warning goes away. The question - how can I override this .gitattibutes setting automatically?

anatoly techtonik
  • 19,847
  • 9
  • 124
  • 140

2 Answers2

7

.gitattributes overrides all config settings, so it really can't be overridden; it is the "overrider," so to speak. While you can simply remove the line, this will cause inconsistent behavior on other developers' machines if they have core.autocrlf=true. So the best bet would be to add the following line to .gitattributes: * -text. This will disable CRLF processing for all files.

David Deutsch
  • 17,443
  • 4
  • 47
  • 54
  • 3
    It would be nice if GIT has some option to turn EOL conversion off completely regardless of the .gitattributes file. In my case the .gitattributes file is maintained by RE and I can't change it but I absolutely want to have all files on my PC with just LF. – Andrei LED Sep 01 '15 at 14:41
  • Thanks so much. I've spent ages battling with a fast-export that had `* text=auto` set. This did the trick. I'd up-vote 10 times if I could! – spikyjt Mar 09 '16 at 15:10
  • 1
    @AndreiLED you can override this per repo, by editing/adding .git/info/attributes. The order of precedence is global config -> .gitattributes in the dir -> .git/info/attributes (i.e. the latter takes highest preference and overrides the others). Reference here: http://git-scm.com/docs/gitattributes – spikyjt Mar 09 '16 at 15:15
  • Thanks, I will give it a try. Though, I already achieved the desired effect by setting core.eol to lf. – Andrei LED Mar 10 '16 at 10:24
7

At least in modern versions of git, .git/info/attributes (or $GIT_DIR/info/attributes) overrides .gitattributes for local configuration.

Use * !text to use the value of core.autocrlf, or * -text to force no conversion.

See the documentation for gitattributes and the text attribute.

Also note: core.eol, the eol attribute

Josh Klodnicki
  • 585
  • 6
  • 18