I modified my .gitconfig
in such a way that I have some colors when performing git diff
:
$ cat .gitconfig
[color]
ui = true
I'm working on an ubuntu machine and I edited some code using VIM. After editing a file a execute 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 don't see those when turning of color.ui
or when looking with vim
, cat
, more
.. at the manipulated file.
It is probably an encoding issue. The 'git diff' command is executing Vim thinking that the file format is Dos.
When you are using any other command, it is correctly recognized as a Unix file.
Can you try :
:set fileformat=unix
in your git diff window ?
I am not really sure this is the root cause, because I don't see the link with the ui
option.
The problem was solved for me by setting core.whitespace
to cr-at-eol
treats a carriage-return at the end of line as part of the line terminator (git-config docs)
This can be added to a per-project or global git config file as follows:
[core]
whitespace = cr-at-eol
This solves the problem of hiding the ^M at the end of lines which were in the diff due to another non-line-ending change. The intention is not to ignore changes where the only difference is the line ending. I am on windows with core.autocrlf
=true
and so the line ending mismatch is expected.
My only caution is that I don't know if this will affect whether git flags up genuine changes in EOL which one might want to commit, but perhaps with autocrlf=true this is never going to be the case.
An alternative fix, more targeted (but slightly more hacky), is described here.
Please have a look at Github's excellent "Dealing with line endings" page:
https://help.github.com/articles/dealing-with-line-endings
You probably want to set core.autocrlf and then re-normalize your repository.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With