0

I am facing a Git (Github.com) issue, that it cannot properly render newlines. Instead, it renders a set of "^M" symbols where newline character (-s) should be.

An image below is an excerpt of a diff:

enter image description here

I have set the git option "git config --global core.autocrlf true". I have also changed the file encoding to UTF-8. Before it was windows-1252 (I have recommited the files). Neither of these actions helped.

Environment details:

  • IDE: PHPStorm 2017.3.6
  • OS: Windows 10
  • Language: PHP

Thank you!

Lukas
  • 13
  • 6

2 Answers2

1

That's an artifact of the previous character encoding you were using, and whatever process you used to convert to UTF-8 didn't convert the newlines properly. The fixes in this question's answers should help you, too: '^M' character at end of lines

Rylab
  • 1,236
  • 7
  • 17
1

UTF-8 is character encoding.

The ^M is a token for a CR character which is part of the end-of-line behavior your editor is using.

The end-of-line behavior is separate from character encoding.

how you set your git config is largely dependent on whether you are working from a windows box, and also whether you intend the code to execute on a windows box. If everything is windows then you should be able to safely set it to

git config --global core.autocrlf false

which will commit the CR+LF (standard windows-style end-of-line) into the repository.

If you code is going to reside on a linux server then you will more likely want to set it to

git config --global core.autocrlf input

which will allow git to convert the CR+LF to LF (standard unix-style end-of-line) only on commits to the repository.

webmite
  • 575
  • 3
  • 6