Not doing git CRLF conversion for .m matlab files?

2019-02-23 14:37发布

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.

2条回答
放荡不羁爱自由
2楼-- · 2019-02-23 15:29

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

查看更多
地球回转人心会变
3楼-- · 2019-02-23 15:37

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.

查看更多
登录 后发表回答