2

So at my workplace, we have many employees using a mixture of Windows and Linux systems, with Eclipse being the official IDE of choice. I'm personally using IntelliJ IDEA, but that's not really relevant... We recently switched from SVN to Git.

One of my co-workers who I am working on a project with has at least three times now managed to accidentally change all of the line endings in the whole repository when he does a merge and then push to origin. I can't figure out how he's managing to do this, but it clearly has something to do with his process of resolving merge conflicts. We're both using Windows, and the repository we're pushing to is on a Linux machine.

We both installed git from https://git-scm.com/download/win, and chose the default options (which afaik, properly handles line endings)... But could egit in Eclipse be doing something differently somehow?

Mirrana
  • 1,601
  • 6
  • 28
  • 66
  • The type of the *server* is irrelevant here. What matters for Git (I cannot speak for Egit) is what you tell Git to do with line endings during checkout and checkin, and whether you ask for a virtual checkout-and-checkin with `merge.renormalize`. Other important variables are `core.autocrlf`, `core.eol`, and any settings in `.gitattributes` (though `.gitattributes` will affect everyone the same way). And, if your friend is using any external *merge tool*, it will matter what that merge tool does (e.g., perhaps *it* forces everything to crlf or lf-only). – torek Apr 02 '17 at 22:07
  • Check both of your `.gitconfig` files. Look for different values to the same configuration parameters. – Thorbjørn Ravn Andersen Apr 02 '17 at 23:07

1 Answers1

1

What you are going to want to do is create a '.gitattributes' file in the root of your repository. This file is unique to your repository and will override any other collaborators .gitconfig settings should they have core.autocrlf, or core.eol set.

# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.c text
*.h text

# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf

# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary 

The above is an example .gitattributes file from here. Of course this will have to be configured to suit your needs.

Here are the steps to update your repository, also taken from here.

git add . -u
git commit -m "Saving files before refreshing line endings"
rm .git/index
git reset
git add -u
git add .gitattributes
git commit -m "Normalize all the line endings"
Jack Gore
  • 3,874
  • 1
  • 23
  • 32