7

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.

Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
Hendrik
  • 4,849
  • 7
  • 46
  • 51

3 Answers3

10

"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

Community
  • 1
  • 1
Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
  • thanks, this worked! I also converted all my files to unix format, seems like the repo I forked from was developed on windows. – Hendrik Mar 24 '12 at 15:17
5

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/

shadyabhi
  • 16,675
  • 26
  • 80
  • 131
  • 2
    Not completely true: it is *part* of a windows newline. On windows newline is `CR LF`, on linux it is `LF` and `CR` is shown as `^M`, on mac newline is (was?) a single `CR`. There is no need to use dos2unix or similar, vim can handle this correctly if you set needed value of `'fileencodings'` option or are fine with always writing `e ++ff=dos`. – ZyX Mar 22 '12 at 17:04
0

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()
Seth Reno
  • 5,350
  • 4
  • 41
  • 44