Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Atom text editor adds "^M" to empty lines

Atom text editor adds this symbol to every empty line.

Any idea what and why?

enter image description here

like image 506
Ivan Chong Avatar asked Jan 25 '16 04:01

Ivan Chong


3 Answers

I'm on Ubuntu Linux and noticed the ^M (Carriage Return, Line Feed) during git diff.

Somehow CRLF was selected at the bottom of the status bar:

CRLF in Atom status bar

I simply clicked it and changed to LF:

LF in Atom Status Bar

It seems to be set on a file-by-file basis so will need to be changed for each problem file.


In my case somehow all the line endings had been changed so git diff was a sea of red. I used the following to identify 'real' changes:

git diff --ignore-space-at-eol

However, git commit would still bury the 'real' changes in commit history so I:

  1. ran git stash save
  2. changed line endings in atom
  3. ran git commit -am "fix line endings"
  4. ran git stash apply

Now the line endings are gone and commits can be made on a precise diff.

like image 83
Pocketsand Avatar answered Sep 20 '22 03:09

Pocketsand


Are you using Atom text editor under Windows?
Windows carriage return is \r\n while it is \n in Unix.
^M ( 0xD or \r ) is the carriage return character in Windows.
I think, that file was previously saved under Unix ( and already have \n on each line), so Atom is adding \r as required by Windows.

For more information you can see this and this

like image 37
Roman Zaitsev Avatar answered Sep 19 '22 03:09

Roman Zaitsev


Check your bottom of the editor which might have changed your file line endings.

Usually it is LF for Unix

enter image description here

and CRLF for windows

enter image description here

like image 24
Praneeth Avatar answered Sep 18 '22 03:09

Praneeth