tags:

views:

195

answers:

2

We have a repository that was exported from subversion into git. This repository is used by Mac, Linux, and PC users. Needless to say the line endings are a mess. Some files end in CRLF, LF, or CR and some have a mix between all two or three in one file.

Adding autocrlf = true seems to fix things slightly. However the diffs come up quite strange at times, ie a one line edit to a file makes all lines appear changed in the diff (I assume it was due to the line endings for the file were all rewritten) and sometimes one line edits to a file works correctly.

Is there a website, or could someone please explain how we can sort this mess out? Is there a git setting we have to set, or do we have to do a bulk update of all the files to have a certain line ending or what?

Any help would be much appreciated as its quite a mess!

(The following stackoverflow post appears it might help, although it doesnt answer what happens when we have another mac or pc or linux user commit another patch)

+3  A: 

I would try, as much as possible, to standardise on a common line ending to be used throughout all source files in your project. A good one to choose might be LF only, however I would check that the editor(s) used by developers handle your chosen common line ending sanely and correctly. (In this case, sanely means not changing every line in the file just because the user changed one line.)

You may need to do a big cleanup job and have one big commit that changes all the file line endings to your chosen standard ending. This will be awkward but probably not as awkward as maintaining a variety of different line endings.

Greg Hewgill
+3  A: 

This related SO question will be of interest to you:

Trying to fix line-endings with git filter-branch, but having no luck

And here is a link to similar advice from Github.

Also, as mentioned in Greg Hewgill's post it is wise to verify that future committers use an editor which handles the new line-ending policy correctly.

When you say "Adding autocrlf = true seems to fix things slightly." I assume this was done in using .gitattributes.

Tim Henigan
So step one: fix the line endings in the repository. Step two: tell people to use `git config --global core.autocrlf true` and then slap them around if they commit without using it?
corydoras
@corydoras: The beauty of `.gitattributes` is that the file can be pushed to the repository. If the `core.autocrlf` is set in a file and pushed, then I believe it should enforce line endings in any clones. However, I am not sure if fresh clones would be needed or if each committer would need to follow the advice given on Github.
Tim Henigan