Published on

Understanding `LF` and `CRLF`

Authors
  • avatar
    Name
    hwahyeon
    Twitter

I've encountered the message serveral times:

"This diff contains a change in line endings from 'LF' to 'CRLF'."
  • LF (Line Feed, \n) represents a line break commonly used in UNIX-based systems (Linux, macOS).
  • CRLF (Carriage Return + Line Feed, \r\n) represents a line break using two characters, primarily used in Windows systems.

For example, in the file

"Hello\r\nWorld"

the \r character might be visible or ignored when viewed on Linux.

So, that message appeared because the file's line endings changed when moving between different operating systems. Although this doesn't affect the code's functionality, it can introduce unnecessary changes in version control.

In version control systems like Git, the core.autocrlf setting can automatically convert line endings.

  • core.autocrlf=true: Typically used on Windows. Converts LF to CRLF when checking out files and reverts back to LF when committing.
  • core.autocrlf=input: Commonly used on Linux. Keeps line breaks as LF without converting them.
  • core.autocrlf=false: Used when the entire team or organization works on the same OS. No line ending conversions are performed.

Global configuration

git config --global core.autocrlf <value>

Local Configuration

git config --global core.autocrlf <value>

To apply this setting to a specific repository, navigate to that repository directory first, then run this command.