Git Line ending issue (CRLF would be replaced by LF) [Git-1]


When you are playing with Git, you may encounter this situation. Which is, more than painful from my point of view:

> git add wordpress-4.4/wp-content/plugins/crayon-syntax-highlighter
fatal: CRLF would be replaced by LF in wordpress-4.4/wp-content/plugins/crayon-syntax-highlighter/crayon_fonts.class.php.

[Git-1] EOL issue with Git - git add before

This mean you have an issue with the Operating System EOL (end of line) file format.

Line endings

To be more specific, the line endings depends of the OS you are on:

  • CR LF for Windows
  • LF for Unix-like systems (GNU/Linux, Apple OS X, Unix)
  • CR for Apple older version (Max OS, …)

The “fatal: CRLF” you are encountering means that the file you are trying to add to your repository is in the Windows line ending format.



1 – Define the Git configuration

The best thing to do is to read the Git documentation about the formatting and whitespaces to have a good understanding of this problem. Then type the following command:

> git config --global core.autocrlf false

2 – My favorite (dos2unix + find)

Another option on an Unix OS like Apple OS X, is to use find combined with the dos2unix command:

> find wordpress-4.4/wp-content/plugins/crayon-syntax-highlighter -type f -exec dos2unix {} \;

[Git-1] EOL issue with Git - find command

It search for all the files in the wordpress-4.4/wp-content/plugins/crayon-syntax-highlighter directory and converted them to the Unix format.


At the end

Finally, I can add the directory and the files it contains to my Git repository:

[Git-1] EOL issue with Git - git add after

Success !

Leave a Reply