[ACCEPTED]-How can I convert all line endings to CRLF, LF, or CR during SVN operations-eol

Accepted answer
Score: 32

I don't think the pre-commit hook can actually change 11 the data that is being committed - it can 10 disallow a commit, but I don't think it 9 can do the conversion for you.

It sounds 8 like you want the property 'svn:eol-style' set to 7 'native' - this will automatically convert 6 newlines to whatever is used on your platform 5 (use 'CRLF', 'CR' or 'LF' to get those regardless 4 of what the OS wants).

You can use auto-properties so that 3 all future files you create will have this 2 property set (auto props are handled client-side, so 1 you'd have to set this up for each user).

Score: 6

First is to clean everything up. Are you 27 on Windows or Unix/Linux/Mac?

If you're on 26 Unix/Linux/Mac, you can try something like 25 this:

$ find . -type f -name "*.java" -exec dos2unix {}\;

That's if you have dos2unix on your box. It's 24 not on my Mac or any of the six Linux machines 23 we have. Seems like we didn't install this 22 particular package. Fortunately, it's easy 21 enough to find.

Be careful using it because 20 you don't want to to munge binary files.

Once 19 you've cleaned everything up, you should 18 put the svn:eol-style property on your files. Setting 17 it to native will checkout the file with the correct 16 line ending for your machine, but store 15 them in Unix line ending format. The other 14 three options are "LF" for Unix, "CRLF" for 13 Windows, and "CR" for pre Mac 12 OS X Macs. Most people find "native" to 11 work out the best. The only problem with 10 Native is that it won't check in a file 9 with mixed line endings while "LF" and 8 "CRLF" will.

Once you do that, you 7 should get a pre-commit hook that will allow you to enforce 6 line endings on particular files. Then, teach 5 your developers to use autoproperties. The pre-commit 4 hook will prevent any commits unless the 3 property is placed on the file A developer 2 gets their commit rejected once or twice, and 1 they'll setup auto properties on their own.

Score: 2

Add a pre-commit hook which parses the file content and 2 performs the munging of CRLF/LF/CR/etc for 1 you before it's written to SVN.

Score: 2

You may consider using a command like Linux's 4 dos2unix for the conversion. Being a Linux command, it 3 is easy to use it in batch mode with scripts 2 etc. I do not know whether there is an equivalent 1 for other operating systems.

Score: 0

you can use notepad++ to batch convert line 6 endings. Make regex search:


and replace it 5 with


you then should choose a bunch of test 4 files like:


this avoids that you accidently 3 modify binary files

NOTE: the regex patterns 2 skip empty lines, so you have to run a second 1 replace job with \n\n and replace it with \n\r\n

More Related questions