Search code examples
phpgitdiffcarriage-return

Migrating a Windows PHP Project to Git and Applying OSX Updates/Patches


I have a Windows based PHP project (CRLF Newlines) that wasn't in any kind of version control. I've recently put that project into Git on my OSX machine. Another developer made changes to the source (on a separate machine) while it wasn't in Git and now I have to merge those changes into the repo.

My original plan was to use diff/patch to get everything synced up. Problem with this is that he made his updates on OSX so I have to convert the newlines in order to make diff/patch work.

Is there a way to make diff work with the CRLF newlines? From what I've read you have to do the conversion first to LF before applying diff.

If not, do I just have to recursively go through all the files and do the newline conversion?

Am I even going about updating this repo in the appropriate way?


Solution

  • When creating the patch, you should be able to tell the tool you use to ignore EOL changes or whitespace changes. Additionally git apply and git am have some options regarding how they handle whitespace but I have not used them so I'm unsure of how they handle diffs with extra whitespace and EOL changes.

    IMHO the real solution though is to correct all the CRLFs in your repo to LFs because git works best if everything uses LF line endings in the repo. If needed there are options to have the line endings changed to CRLF on checkout while still using LF internally.