5

Matlab .m files use the Unix LF line endings even on Windows. I'm look to set up the git config file so that the .m files are not converted back to CRLF as other regular text files would be (i.e. I am using LF as the default style within the repo, even though its Windows).

Can this be done?

EDIT: from Matlab 2008b manual. (under Editing and Debugging M-Files)

Line Endings Removed in Files Provided with MATLAB Software for Windows Platforms; Impacts Viewing in Notepad Application

In previous versions, text files provided with MATLAB for Windows platforms included a carriage return and line feed at the end of each line. Starting in R2007b, the text files MATLAB provides do not include a carriage return and line feed at the end of each line.

File types affected are: .asc .bat .c .cc .cdr .cpp .def .for gs.rights .h .ini .m .mdl .pl readme .tlc .tmf .txt

There is no impact if you view the files in MATLAB and other common text editors, with the known exception of the Microsoft Notepad application.

Compatibility Considerations. If you use the Notepad application to view files provided with MATLAB, you see carriage return and line feed symbols instead of line endings. This makes the files less readable in the Notepad application. Other text editors might display the symbols instead of line endings, but of the common text editors tested, none have been found that do so.

As an alternative to the Notepad application, use the Microsoft WordPad application, provided with Windows platforms, or another text editor to view the files.

Mr_and_Mrs_D
  • 27,070
  • 30
  • 156
  • 325
Philip Oakley
  • 11,745
  • 8
  • 42
  • 63

2 Answers2

3

Set the core.autocrlf config to false and core.eol to lf on Windows.

[core]
    autocrlf = false
    eol = lf

Also, have a look at gitattributes under Checking-out and checking-in

manojlds
  • 259,347
  • 56
  • 440
  • 401
  • 1
    so in gitattributes I'll need `*.m eol=lf` then ? (same as the *.sh example in the man page) – Philip Oakley Jul 25 '11 at 22:58
  • @Philip Oakley - Yes, you can have `*.m eol=lf` in `.gitattributes` – manojlds Jul 25 '11 at 23:23
  • :@manojlds: Isn't it 'autocrlf = true' for general windows text files being normalised to LF in the repo, and then checked out as CRLF in the working directory? [The .gitattributes file catching the matlab files as being different on check out] – Philip Oakley Jul 26 '11 at 14:37
  • I also forgot `safecrlf=true` which I need to try with this mixed file type scenario. – Philip Oakley Jul 27 '11 at 18:41
  • I tried the `safecrlf=true` with mixed results. Initially I'm building a history of old work. For those files I needed it off (I commented it out with a #) as some of the files weren't normalised (i.e. I had mixed CR and CRLF between files so wouldn't check in and check out unchanged; but I do want to normalize them!). Once I've done the hisrory the current files should already conform so I should be able to re-instate `safecrlf=true` – Philip Oakley Jul 28 '11 at 09:00
0

Change autocrlf to false. set core.whitespace to cr-at-eol (This will ensure you don't get ^M highlighted as problematic whitespace in diffs and patches). Use vim or another editor to ensure you have lfs in your .m files.

Adam Dymitruk
  • 109,813
  • 21
  • 138
  • 137