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

核能气质少年 提交于 2019-12-05 04:22:15
Lazy Badger

"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

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/

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()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!