Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "!eol" in gitattributes do?

Recently I came across the following entry in a .gitattributes file:

"* text=auto !eol"

What does !eol do?

like image 752
user3226810 Avatar asked Jan 23 '14 08:01

user3226810


People also ask

What is the purpose of Gitattributes file?

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.

Does Gitattributes override Autocrlf?

gitattributes not override core.

How does git handle line endings?

text eol=crlf Git will always convert line endings to CRLF on checkout. You should use this for files that must keep CRLF endings, even on OSX or Linux. text eol=lf Git will always convert line endings to LF on checkout. You should use this for files that must keep LF endings, even on Windows.

Should I use CRLF or LF?

Whereas Windows follows the original convention of a carriage return plus a line feed ( CRLF ) for line endings, operating systems like Linux and Mac use only the line feed ( LF ) character. The history of these two control characters dates back to the era of the typewriter.


3 Answers

Git has 2 attributes that deal with end-of-lines:

  1. text

Documentation says:

This attribute enables and controls end-of-line normalization. When a text file is normalized, its line endings are converted to LF in the repository

This effectively means that when you commit to the repo, it will convert line-endings to LF

  1. eol

Documentation says:

This attribute sets a specific line-ending style to be used in the working directory. It enables end-of-line normalization without any content checks, effectively setting the text attribute.

So while the text attribute affects how the file will look like IN THE REPO, eol affects how the file looks like in the working directory.

Now, an attribute can have 4 states:

set with no value
example: * text

unset
example: * -text

set with specific value
example: * text=auto

unspecified
example: * !text

So, * text=auto !eol means this:

All files have the attribute text set to auto and the eol attribute unspecified. Reading the documentation we find out that text=auto means that you let Git decide if a file is text and if it is it will normalize it (set line-endings in the repo to LF).

!eol means that the attribute eol is set to unspecified explicitly. In this case it is the same as not specifying it at all, instructing Git to look at the core.autocrlf and core.eol configuration settings to see how to deal with line-endings in the working directory. Note this:

The core.eol configuration variable controls which line endings Git will use for normalized files in your working directory; the default is to use the native line ending for your platform, or CRLF if core.autocrlf is set.

But you would use !eol in a situation like the following:

* text=auto eol=crlf
test.txt !eol

basically overriding the eol attribute from CRLF to unspecified for test.txt. This means that for all files except test.txt, Git will convert line-endings to CRLF on checkout. For test.txt Git will defer to the core.autocrlf and core.eol configuration settings so on any given system the line-ending may be either LF or CRLF.

like image 198
andrei.serea Avatar answered Oct 12 '22 14:10

andrei.serea


* text=auto !eol

implies:

  • no EOL (end of line) conversion would be performed for binary files.
  • for text files, EOLs are converted to OS-dependent EOL (convert to LF for Unix and CR+LF for Windows) upon checking out the file and replaced with LF while checking in.
like image 22
devnull Avatar answered Oct 12 '22 13:10

devnull


It basically disables eol according to the documentation:

Sometimes you would need to override an setting of an attribute for a path to Unspecified state. This can be done by listing the name of the attribute prefixed with an exclamation point !.

eol does the following:

This attribute sets a specific line-ending style to be used in the working directory. It enables end-of-line normalization without any content checks, effectively setting the text attribute.

like image 4
Agis Avatar answered Oct 12 '22 13:10

Agis