开发者

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 CR开发者_如何学运维LF 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?


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.


Sweet!

First I needed to get rid of all the CRLFs. I killed my entire git repo with rm -rf .git/. Then I loosely followed GitHub's Dealing with Line Endings which is from this stackoverflow Q&A.

# switch on the conversion of line endings on commit
$ git config --global core.autocrlf input

# Initialize
$ git init
$ git add .
$ git commit -m "First Import"

# If you're doing this on a Unix/Mac OSX clone then optionally remove
# the working tree and re-check everything out with the correct line endings.
$ git ls-files -z | xargs -0 rm
$ git checkout .

I then ran diff and patch against the appropriate folders and ran the final commit. Everything is synced up!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜