Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+35 votes

Sometimes when I am trying to merge changes on git, it shows that the whole file (or huge chunks of it) are different, even when they don't look different to me!

What's going on here?

asked in CSC285_Fall2018 by (17.9k points)

1 Answer

+13 votes

Under the hood, text files consist of characters. Traditionally on Mac & Linux computers,
every new line is represented by one new line character ('\n', called a "line feed" / "LF" character, ASCII code 10). Traditionally, on Windows computer, every new line is represented two characters ('\r', called a "carriage return" / "CF" character, ASCII code 13, followed by a '\n'). Why? This goes back to the days of manual typewriters (see https://www.youtube.com/watch?v=EiyZSX0OnBM), where there were two steps in going to a new line -- returning to the left side of the page, and going down one line.

Anyway, git prefers the Mac/Linux one-character version, but it can handle auto-conversion between the Windows-style (CR LF) line endings on Windows, but only if you set the core.autocrlf configuration to true. This is the default setting when you install on git on Windows, BUT for some reason the Eclipse git plugin isn't seeing that value. To solve this problem:

IF you are using a Windows computer (but NOT if you are on Mac or Linux), you should run the following command from "git bash":

git config --global core.autocrlf true

Unfortunately, because of deep freeze, you'll need to run this command every time you use the lab computers until I have time to go around to each machine, unfreeze it, reboot, change this setting, refreeze it, and reboot again... hopefully sometime next week I'll get to them all!

Also, unfortunately, if you've already committed files to a repository that have the wrong line ending characters, then after this change you may have some more problems for a while until all of the problematic files get converted to the correct line endings.

Another way to avoid any problems like this would be if everyone uses Git Bash to do all your committing, instead of using the Eclipse Team GUI method.

In any case, I'm hoping we can get this configuration all sorted out before you start working with your real teams' repos!

answered by (17.9k points)
...