5

Issue

Running Windows on Mac via Parallels we can't seem to figure out the right Git settings so that we don't get line ending file changes.

Details

The Git repo is on the Windows vm and is a shared drive that we can access on our Mac so we can edit our Angular code.

I've read many of the articles on StackOverflow, but they don't seem to solve the problem.

Is it possible to be in Windows and working on a cSharp file, and make commits from the command line.

Then slide over to Mac, edit some javascript, and then in a mac terminal make a commit without constantly having line ending changes on other unrelated files?

We've been playing with core.autocrlf and core.eol and .gitattributes but it seems like not matter what we do, one OS or the other will show tons of file changes( which end up being line endings) but our editors are not making the change.

I can just do a clone on windows, and then on mac do a git status and it will make it look like every file changed.

Question

What do the settings need to be?

Step 1: On Windows

git config --global --unset core.eol
git config --global core.autocrlf true

// on a new branch

git rm --cached -r .
git reset --hard
git commit "Reset Line Endings" //(I expected this to be larger).
[line 4d14aa1] Reset EOL
9 files changed, 12910 insertions(+), 12910 deletions(-)

git status

$ git status
On branch line
nothing to commit, working directory clean

Step 2: On Mac

git config --unset core.eol
git config --global core.autocrlf input
git status
modified:   tools/NUnit2.5.3/nunit-agent-x86.exe.config
modified:   tools/NUnit2.5.3/nunit-agent.exe.config
modified:   tools/NUnit2.5.3/nunit-console-x86.exe.config
modified:   tools/NUnit2.5.3/nunit-console.exe.config
modified:   tools/NUnit2.5.3/nunit-x86.exe.config
modified:   tools/NUnit2.5.3/nunit.exe.config
modified:   tools/NUnit2.5.3/pnunit-agent.exe.config
modified:   tools/NUnit2.5.3/pnunit-launcher.exe.config
modified:   tools/NUnit2.5.3/runFile.exe.config
modified:   tools/NUnit2.5.3/runpnunit.bat
modified:   tools/NUnit2.5.3/test.conf
modified:   tools/StyleCop 4.3.1.3/ReSharper-code-style-settings.xml
modified:   tools/StyleCop 4.3.1.3/Settings.StyleCop
...(100's of other files)

Step 3: On Windows

git status
Same output as above

.gitattributes

* text=auto

# These files are text and should be normalized (convert crlf => lf)
# Git Files
.gitattributes text
.gitignore text
.gitconfig text

# cSharp / Visual Studio

*.bat     text eol=crlf
*.cmd     text
*.cs      text  diff=csharp eol=crlf
*.csproj  text
*.h       eol=crlf
*.md      text
*.msbuild text
*.ps1     text
*.sdf     binary
*.sln     text  eol=crlf
*.tt      text
*.xaml    text

# Web
*.css     text
*.sass    text
*.json    text
*.js      text
*.htm     text
*.chm     binary
*.html    text
*.xml     text
*.svg     text  eol=lf

# Images & Media
*.png     binary
*.jpg     binary
*.jpeg    binary
*.gif     binary
*.ico     binary
*.mov     binary
*.ico     binary
*.pdf     binary


# Compression
*.gz      binary
*.zip     binary
*.7z      binary
*.nupkg   binary

# Fonts
*.ttf       binary
*.eot       binary
*.woff      binary

# Documents
*.doc  diff=astextplain
*.DOC  diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot  diff=astextplain
*.DOT  diff=astextplain
*.pdf  diff=astextplain
*.PDF  diff=astextplain
*.rtf  diff=astextplain
*.RTF  diff=astextplain
*.md text
*.adoc text
*.textile text
*.csv text
*.tab text
*.tsv text
*.sql text
*.psd binary
*.ai binary
*.eps binary

# Compiled Dynamic libraries
*.so      binary
*.dylib   binary
*.dll     binary
*.pdb     binary

# Compiled Static libraries
*.lai   binary
*.la    binary
*.a     binary
*.lib   binary
*.llblgenproj binary

# Executables
*.exe binary
*.out binary
*.app binary

# Security
*.p12 binary
*.cer binary
Mark Evans
  • 810
  • 10
  • 18

1 Answers1

1

My recommendation to you would be to have your entire development team agree on a common code format, including line endings. This way, there will never be any friction when one developer attempts to commit a file on Windows which was last edited on a Mac (i.e Linux). Git is being gracious by telling you that the line endings might change. However, I believe the better way to handle this is not to rely on Git, but to just agree on a common format across all machines.

In many software jobs I have had, I have seen problems with code formatting. This is not limited to line endings, but could also be related to spacing and tabs. Having everyone agree on a format can save time and avoid unnecessary merge conflicts.

Here are links for how to configure line ending separators in the major IDEs:

IntelliJ
Eclipse
Netbeans

Community
  • 1
  • 1
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • 1
    And then after, you could add these choice in a config file, store it in the repository and use [editorconfig](http://editorconfig.org/) ;-) – Philippe Oct 23 '15 at 06:37