Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override .gitattributes text=auto in Windows

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?

like image 220
anatoly techtonik Avatar asked Jun 22 '15 11:06

anatoly techtonik


People also ask

Does Gitattributes override Autocrlf?

gitattributes not override core.

What does text auto do Gitattributes?

When text is set to "auto", the path is marked for automatic end-of-line conversion. If Git decides that the content is text, its line endings are converted to LF on checkin. When the file has been committed with CRLF, no conversion is done.

Where is. gitattributes stored?

These path-specific settings are called Git attributes and are set either in a . gitattributes file in one of your directories (normally the root of your project) or in the . git/info/attributes file if you don't want the attributes file committed with your project.

What is. gitattributes used for?

gitattributes file allows you to specify the files and paths attributes that should be used by git when performing git actions, such as git commit , etc. In other words git automatically saves the file according to the attributes specified, every time a file is created or saved.


Video Answer


2 Answers

.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.

like image 77
David Deutsch Avatar answered Sep 18 '22 23:09

David Deutsch


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

like image 39
Josh Klodnicki Avatar answered Sep 20 '22 23:09

Josh Klodnicki