Richard A Quadling
Richard A Quadling

Reputation: 3988

How should I configure git line endings for non Windows hosts with Windows VMs?

We develop on Windows and use git. Locally, line endings are CRLF and all the magic in between means that the files on our production server (CentOS) will have LF. Everyone is happy.

We also use a Windows only tool to generate a LOT of the files for us (PHP Maker). This app generates files with Windows line endings.

Still all good.

But, we have 2 non Windows developers (one on a Mac, one on Ubuntu Mate). For the non PHP Maker generated files, their editors work with files that have their OS specific line endings and all the magic in between means that those files end up with the correct line endings on our production server. And when the Windows developers interact with the non PHP Maker files, it is still all good with CRLF line endings locally.

Everything seems fine.

Right up to the point where the non Windows developers have to run the PHP Maker application in their Windows VM on their Mac/Ubuntu machines.

Then things seem to go a little wonky.

The net effect is that when these developers run PHP Maker and commit from their development machines (not the VM), the line endings seem to get ... confused ... and somehow when the windows developers get hold of these files, they are 100% whitespace different - and it is JUST line endings.

I'm willing to do research but I don't know enough to work this out as I am only on Windows (where it all just works as expected) and don't have access to the Mac/Ubuntu setups to diagnose the issue.

So. What am I supposed to do? We have no issue enforcing things one way or the other (as in "for good or bad, this is how we want things setup").

But some ideas, suggestions, recommendations, perfect answers, etc. are all appreciated.

Regards,

Richard Quadling.

Upvotes: 0

Views: 109

Answers (1)

Richard A Quadling
Richard A Quadling

Reputation: 3988

The solution we came up with is to use .gitAttributes.

Here is what ours contains.

# Auto detect text files and perform LF normalization
*           text=auto

# Force text mode
*.css       text
*.html      text diff=html
*.inc       text
*.ini       text
*.js        text
*.json      text
*.lock      text
*.md        text
*.php       text diff=php
admin/*.*   text eol=crlf
*.pmp       text eol=crlf
*.reg       text
*.sql       text
*.template  text
*.txt       text
*.xml       text
*.yml       text
.git*       text
.htaccess   text
PHPMaker/Extensions/*.xml text eol=crlf

# Force binary mode
*.eot       binary
*.gif       binary
*.ico       binary
*.jpg       binary
*.otf       binary
*.pay       binary
*.pdf       binary
*.png       binary
*.svg       binary
*.ttf       binary
*.woff      binary
*.zip       binary

All the files in admin are generated, so making them all windows line endings, along with some other windows based files (the generator and some extensions), all made this work once we had got things in place.

Beside using this file, we had to rebuild the index.

To do that, we followed this list of commands.

git rm --cached -r .
git reset --hard
git add -A
git commit -m "Normalize all the line endings"

We got a lot of warning messages saying "CRLF will be replaced by LF", but that is normal and expected.

Did this in each branch that cannot currently be rebased off master or develop and we were done.

Now we have Windows, OSX and unix developers (with Windows VMs for non Windows devs for the PHPMaker builder) all working harmoniously.

I hope this helps someone.

Upvotes: 1

Related Questions