I had to move my Eclipse workspace from Linux to Windows when my desktop crashed. A week later I copy it back to Linux, code happily, commit to CVS. And alas, windows newlines have polluted many files, so CVS diff dumps the entire file, even when I changed a line or two!
I could cook up a script, but I am wondering if it will mess up my Eclipse project files.
You could give it a try. The problem is that Windows inserts a carriage return as well as a line feed when given a new line. Unix-systems just insert a line feed. So the extra carriage return character could be the reason why your eclipse messes up with the newlines.
Grab one or two files from your project and convert them. You could use Notepad++ to do so. Just open the file, go to Format->Convert to Unix (when you are using windows).
In Linux just try this on a command line:
sed 's/$'"/`echo \\\r`/" yourfile.java > output.java
To recursively remove the carriage returns (\r
) from the CVS/* files in all child directories, run the following in a unix shell:
find ./ -wholename "\*CVS/[RE]\*" -exec dos2unix -q -o {} \;
There is a handy bash utility - dos2unix
- which is a DOS/MAC to UNIX text file format converter, that if not already installed on your distro, should be able to be easily installed via a package manager. dos2unix man page
In addition to the Eclipse solutions and the tool mentioned in another answer, consider flip. It can 'flip' either way between normal and Windows linebreaks, and does nice things like preserve the file's timestamp and other stats.
You can use it like this to solve your problem:
find . -type f -not -path './.git/*' -exec flip -u {} \;
(I put in a clause to ignore your .git directory, in case you use git, but since flip ignores binary files by default, you mightn't need this.)
Source: Stackoverflow.com