Hendrik
Hendrik

Reputation: 4939

^M characters in git commit message (git commit -v)

I am having a weird problem where lots of ^M characters show up in my git commit message. Please find a screenshot attached. This is not causing any problems, just makes it annoying to read through.

enter image description here

Tips appreciated.

Upvotes: 7

Views: 3835

Answers (3)

Seth Reno
Seth Reno

Reputation: 5450

I'm on windows and did not want to set autocrlf to true. I worked around the issue by putting the following in my .vimrc

" settings for git commit messages
function GitCommitSettings()
    %s/^M//g               " remove ^M added by git diff
    syntax sync fromstart  " refresh syntax highlight after replace
    1                      " move to line 1
endfunction
au BufNewFile,BufRead COMMIT_EDITMSG call GitCommitSettings()

Upvotes: 0

Lazy Badger
Lazy Badger

Reputation: 97395

"The Proper Way", if you use Git in cross-platform environment, contrary to Abhijeet's answer, is:

Learn and CORRECTLY configure core.autocrlf settings in each client

Read local topic "Why should I use core.autocrlf=true in Git?" as good starting point

Upvotes: 10

shadyabhi
shadyabhi

Reputation: 17244

Thats a windows newline. Newlines in and windows & linux are different.

You can remove it using dos2unix.

Various ways of doing it: http://www.cyberciti.biz/faq/howto-unix-linux-convert-dos-newlines-cr-lf-unix-text-format/

Upvotes: 5

Related Questions