Git diff shows ^ M with color ui true

I changed my .gitconfig so that I have several colors when doing git diff :

 $ cat .gitconfig [color] ui = true 

I work on an ubuntu machine and I edited the code using VIM. After editing the file, do git diff , once with and once without ui=true .

Problem : in the first case, I have ^M characters and the end of the edited lines. However, I do not see them when I turn color.ui or when viewing with vim , cat , more .. in a managed file.

+6
source share
3 answers

This is probably an encoding issue. The git diff command executes Vim, assuming the file format is Dos.

When you use any other command, it is correctly recognized as a Unix file.

Can you try:: :set fileformat=unix in a git diff window?

I am not sure if this is the main reason, because I do not see the link with the ui option.

+13
source

Take a look at Github’s great “End of Line” page:

https://help.github.com/articles/dealing-with-line-endings

You probably want to install core.autocrlf and then re-normalize your repository.

+1
source

The problem was resolved for me by installing core.whitespace in cr-at-eol

treats carriage returns at the end of a line as part of a line terminator (git -config docs)

This can be added to the configuration file for each project or global git as follows:

 [core] whitespace = cr-at-eol 

This solves the problem of hiding ^ M at the end of lines that were in diff, due to a change other than line. The intention is not to ignore the changes in which the only difference is the end of the line. I am in windows with core.autocrlf = true , so line end mismatch is expected.

My only caveat is that I don’t know if this will affect whether git will create genuine EOL changes that could be committed, but maybe with autocrlf = true it never will.

An alternative fix, more targeted (but slightly more hacked), is described here .

0
source

All Articles