u123
u123

Reputation: 16287

.gitattributes and default line endings

In my .gitattributes I have (Case 1):

###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf

I have also tried (Case 2):

###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
#* text=auto

# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf

Will the general case work and allow *.sln files to always use crlf or will the general case override specialized cases (Case 1)?

It does not seem that the two cases have any different effect.

Upvotes: 0

Views: 2514

Answers (1)

twalberg
twalberg

Reputation: 62389

When processing .gitattributes, every pattern that matches a file is contemplated, with the later ones overriding the earlier ones. So in this case, for *.sln, you end up with the attributes text eol=crlf, because the text overrides the text=auto. In "Case 2" the text=auto isn't there to begin with, so it's not overridden, but the end result set of attributes is still the same, which explains why your two cases don't display different behavior.

The result of having text set is that:

      Set    Setting the text attribute on a path enables end-of-line normalization and marks the path as a text
             file. End-of-line conversion takes place without guessing the content type.

Also, the way I read it, eol=crlf sort of overrides text, and enforces CR/LF style line endings without bothering to check that the file is actually a text file:

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

      Set to string value "crlf"
             This setting forces git to normalize line endings for this file on checkin and convert them to CRLF
             when the file is checked out.

Read through git help attributes for more information...

Upvotes: 1

Related Questions