Search code examples
gitvimcentosphpstorm

.gitattributes file not converting line endings


I have created a .gitattributes file in the root dir of my git install (CentOS). I have created test files in PHPStorm via a samba share connection and specifically set the line endings to CRLF. I add and commit the test file, expecting the file to have the line endings changed to LF, but when I check the file in vim it says: [noeol][dos] next to the file name when I open the file. It seems like the .gitattributes file is not converting to LF... am I incorrect? I am fairly sure I have the attributes set up properly (see below). Am I doing something wrong?

# Set the default behavior, in case core.autocrlf is not set
* text=auto

# Explicitly declare text files you want to always be normalized and  converted to native line endings
*.htm text
*.html text
*.tpl text
*.css text
*.js text
*.php text
*.xml text
*.txt text
*.ini text
*.inc text
*.bak text
*.pm text
*.cgi text
.htaccess text

# Denote all files that are truely binary and should not be modified
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.ico binary
*.mov binary
*.mp4 binary
*.mp3 binary
*.flv binary
*.fla binary
*.swf binary
*.gz binary
*.zip binary
*.7z binary
*.ttf binary

Solution

  • Git conversions happen to the destination of whatever operation you're performing, and you can have different ones on the way into and out of the repo. Here you're telling it to convert text eol's both ways but haven't actually pulled any content from the repo yet. Do a git reset --hard to force a refresh of your current worktree from the committed content using any new filters/attributes. Since git 2.16 you can also use

    git add --renormalize .
    

    It might be a bit counterintuitive that text attribute processing governs what happens on the way into the repo, and core.eol governs what happens on the way out:

    text
    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. To control what line ending style is used in the working directory, use the eol attribute for a single file and the core.eol configuration variable for all text files.