Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git commit show total file replacement instead of line by line changes

Each time a colleague sends me a pull request and I view it at GitHub some of the files in the commit show up like completely new content e.g. 1200 line deletions and 1220 line additions where he as actually only added 20 new lines.

The files have not been reformatted and to the eye look barely changed and yet Git shows 100% pink followed by 100% green.

Any ideas what could be causing this would be very gratefully received.

like image 458
Geraint Avatar asked Dec 12 '25 09:12

Geraint


1 Answers

A real example would help but, most likely...

New lines

The line endings are different. Github has a helpful page explaining how to configure git so that it will transparently handle these differences:

git config --global core.autocrlf input
# Set this setting on OSX or Linux

git config --global core.autocrlf true
# Set this setting on Windows

You can also solve the problem by modifying editor settings.

See non-whitespace changes only

git diff can be used to see actual differences ignoring whitespace. It has various modes e.g.:

git diff --ignore-space-change someotherbranch

will output a diff ignoring differences that are indentation and line endings.

like image 196
AD7six Avatar answered Dec 13 '25 23:12

AD7six