Reputation: 444
I have been working on a project for a while using git. I always use Brackets, usually on Ubuntu but some times also on Windows. The point is that now, on Ubuntu, when I try to submit some changes to my project, I see it added ^M at the end of each modified line.
If I'm not wrong, this is the end of line character for Windows. This is why it puzzles me: why is Ubuntu adding it? And the most important question, what can I do to get rid of them?
I tried different text editors without luck.
Upvotes: 2
Views: 2678
Reputation: 480
The ^M
is the carriage return character. You are seeing this because you are looking at a file in Unix that was created in DOS (Windows). In DOS the end-of-line
is composed of a Carriage Return (CR) (ASCII 13, \r
) and a Line Feed (ASCII 10, \n
) (LF), this is known as CR-LF \r\n
. In Unix, the end-of-line
is marked by a single newline \n
. This is why you get the carriage-return ^M
right before the end-of-line since that is the way how \r
is displayed in Unix. You can fix this with Vim.
Open your file with Vim
Vim <file_name>
with :e you will reload the file in Vim and ++ff=dos will convert the file with dos file format. Now your file is read as a Windows file and all ^M
disappeared
:e ++ff=dos
Now use :set ff=unix to convert the file to Unix format.
:set ff=unix
Finally do :wq to save and exit.
:wq
If you'll like to know more ways to fix this problem check them out in here: Convert between Unix and Windows text files
Upvotes: 3