Search code examples
gitvirtual-machinevmware-fusion

Git Line Endings: Mac to Windows VM


I'm developing on a Mac for a website running locally on a Windows virtual machine (VMware Fusion). The files are in a shared directory, so both OS's are using the same files.

When I edit files on Mac and run them in the Windows VM, I'm getting errors stating "Unexpected end of file" and "Unexpected character in input '".

In my .gitattributes file, I have * text eol=crlf, and when I commit, the errors no longer appear for the modified/committed files.

First, can someone tell me if my diagnosis is correct: that the Mac line endings aren't converted to Windows until the files are committed, and that this is resulting in the "syntax-style" errors when running the files on the Windows VM?

Second, is there a way I can configure my Git repository and/or my VM so that both OS's get their preferred line endings?


Solution

  • 1) Yes, the text eol setting alone does only have an effect during checkout. When you add/commit a file with different line endings, you should also get this kind of warning:

    warning: LF will be replaced by CRLF in <file you want to commit>.
    The file will have its original line endings in your working directory.
    

    2) .gitattributes is not sufficient when you want to have the correct line endings before interacting with your Git repository. You might check your text editor if it is able to configure the line endings. Most of the text editors are capable of that (however, MAC's TextEdit isn't AFAIK).