views:

711

answers:

5

This happens repeatedly and is very annoying. I upload some PHP code to a client's server. A few weeks pass. They ask for a change to be made and I re-download the code as they've made some changes. However, my code which used to be neat and tidy the last time I looked at it now has an extra lines of whitespace added everywhere. So now where I had two lines of space between some code, it now has 3. Where I had a bunch of lines sticking together because they were part of the same for loop or such, they're all scattered around now and there's no way to distinguish them.

Is there any program/utility to fix this?

+7  A: 

Upload in binary mode instead of ascii. Ascii mode is changing all your linefeeds (unix end of line character) into carriage returns + linefeeds (Windows end of line characters).

Paul Tomblin
You're probably right and I'll ask him to use binary in future. But, how can I fix the files that've already been ruined?
@Annoyed - I do it in gvim by typing "%s/^V^M/^V^M/g" (where ^ represents a control character).
Paul Tomblin
+1  A: 

You may also be having a problem with the other editor using tabs when you are using spaces (you are using spaces, right?). I have seen similar problems when sharing source between developers on Linux/OSX and Windows.

Brian C. Lane
+1  A: 

I'll bet this is caused by systems trying to convert text files created in a Windows System to files being used by a Unix/Linux system (and back again).

Windows uses both a carriage return and a line feed and I think Unix uses only a line feed (or was it a carriage return).

I used Ultra Edit as my main text editor (not that Emacs and vi don't rule :o) and it has a DOS mode and a Unix mode for just this kind of thing.

wcm
+1  A: 

Force your client to transfer all files in binary mode. This is also useful when you have unicode text in your files, you never know what assumptions text-mode might make!

hasen j
+1  A: 

At a guess, I would say that you are developing on a Unix / Max system, but the customer is running on a Windows system (or vice-versa). I would also guess that you are uploading / downloading your files in Binary mode. The windows editor is probably converting the Unix LF to a LF/CR pair, which your editor thren treats as two new lines. If you upload and download in ASCII mode, the files will be automatically converted between the two formats.

Simon Callan