DEV Community

Cover image for CRLF — The line break character
Mohamed Yahia
Mohamed Yahia

Posted on

CRLF — The line break character

Usecase

Just yesterday, after i committed my lovely work on windows through vscode source control feature, I did a git status through wsl and then I find multiple files that are modified. So they are modified files in wsl terminal but not on powershell, not on git bash and certainly not on vscode.

I did a git diff to investigate the issue and i find that all the lines in all files are highlighted in both versions except that they are the same. So why was git telling me there are changes when there was not, I wondered.

I investigated the issue furthur through google and i found that the issue lies within the line break character which differs in windows from unix/unix-like systems.

Line breaks (windows vs unix)

In unix, the line break character is the linefeed character LF but in windows it is both a carriage-return CR and a linefeed character, hence CRLF.

By default, git commits whatever line character is in the text but when you turn on core.autocrlf in the repo or globally by $ git config --global core.autocrlf true what git does, is it will convert LF characters to CRLF when viewed on windows but it will convert CRLF to LF when you commit code. So the repo will have LF characters.

This feature should always be turned on if you are working on windows.

If you are on linux, you could do $ git config --global core.autocrlf input this will convert any CRLF characters to LF but not the other way around.

Top comments (0)