skift
skift

Reputation: 1027

Unable to get rid of git line ending issues

On a current project, we have multiple users editing the repository from multiple machines such as Windows, OSX, and Ubuntu. I have tried various settings to keep the line endings normalized, but I continuously get notices that random files in the repo will have its line endings change.

First off, I have this git attributes file in my repository:

# These settings are for any web project

# Handle line endings automatically for files detected as text
# and leave all files detected as binary untouched.
* text=auto

#
# The above will handle all files NOT found below
#

# Documents
*.doc      diff=astextplain eol=lf
*.DOC      diff=astextplain eol=lf
*.docx     diff=astextplain eol=lf
*.DOCX     diff=astextplain eol=lf
*.dot      diff=astextplain eol=lf
*.DOT      diff=astextplain eol=lf
*.pdf      diff=astextplain eol=lf
*.PDF      diff=astextplain eol=lf
*.rtf      diff=astextplain eol=lf
*.RTF      diff=astextplain eol=lf
*.md       text             eol=lf
*.adoc     text             eol=lf
*.textile  text             eol=lf
*.mustache text             eol=lf
*.csv      text             eol=lf
*.tab      text             eol=lf
*.tsv      text             eol=lf
*.sql      text             eol=lf

# Graphics
*.png  binary
*.jpg  binary
*.jpeg binary
*.gif  binary
*.ico  binary
*.svg  text eol=lf

# These files are text and should be normalized (Convert crlf => lf)
*.md       text eol=lf
*.adoc     text eol=lf
*.textile  text eol=lf
*.mustache text eol=lf
*.csv      text eol=lf
*.tab      text eol=lf
*.tsv      text eol=lf
*.php      text eol=lf
*.css      text eol=lf
*.js       text eol=lf
*.json     text eol=lf
*.htm      text eol=lf
*.html     text eol=lf
*.xml      text eol=lf
*.txt      text eol=lf
*.ini      text eol=lf
*.inc      text eol=lf
*.pl       text eol=lf
*.rb       text eol=lf
*.py       text eol=lf
*.scm      text eol=lf
*.sql      text eol=lf
.htaccess  text eol=lf

# These files are binary and should be left untouched
# (binary is a macro for -text -diff)
*.mov  binary
*.mp4  binary
*.mp3  binary
*.flv  binary
*.fla  binary
*.swf  binary
*.gz   binary
*.zip  binary
*.7z   binary
*.ttf  binary
*.pyc  binary

and I have set these git settings on the machines (windows and osx and linux):

git config --global core.eol lf
git config --global core.autocrlf false

Yet I will intermittently get notification from git (cli) that when I pull changes from out development server (which is updated with changes from testing at the end of the day), I get the message stating that CRLF will be converted to LF on commit.

Although lately, I noticed that My cohort and I (on windows) have not been getting these messages as often. But others on mac/linux seem to get them every time they re-checkout the remote branch (even after deleting the local version). When running

git checkout -b develop -t origin/develop

where they should have a perfectly clean directory, they will have anywhere from 1-6 files that show changes. Which are only line endings. And no matter what we do, we cannot get rid of them without committing them. Even though they get committed and pushed directly back up to develop, another dev after fetching will pull a new develop branch (after deleting the local develop branch) will get another random file that states will have its CRLF endings converted to LF.

Upvotes: 1

Views: 417

Answers (1)

Philip Daniels
Philip Daniels

Reputation: 1024

You might want to take a look at a question of mine also dealing with line endings

Git line endings after normalization

I maintain that the answer is to stop git doing any normalization by adding the following to your .gitattributes

* -text
* whitespace=cr-at-eol

and this then puts you in control - all you have to do is set every file to the line ending that you want, a one-off operation. Magic conversion of line endings is a holdover from an era when editors on different operating systems could only handle files with their native line endings (IMNSHO). This is only a problem nowadays if you are coding using Notepad :-)

Upvotes: 1

Related Questions