SVN: Problems Applying a Patch Cross-platform

Suppose you have a set of changes on a Windows machine ready for commit. However, before committing, you’d like to check compilation on your Linux box. So, you create a patch file with a command such as

C:\my-dir> svn diff > patch.diff

Having copied the patch to your Linux box, you try the command

/home/me/my-dir$ patch -p0 < patch.diff

Unfortunately, you see many problems of the form

Hunk #1 FAILED at 234.

What is wrong?

There is a number of reasons why a patch might fail. However, one rather obscure possible reason is that `patch` might be having difficulties with line endings.

There are a few possibilities for getting around this:

  • run the `dos2unix` command on the offending files, optionally followed by `unix2dos` after the patch;
  • set the SVN property `svn:eol-style=native` on the offending files and commit
    (this is a permanent solution, but may or may not be appropriate for your files);
  • use directory sharing or samba, and a program such as WinMerge on the Windows box;
  • commit your changes from Windows to a new private branch for testing only, and switch to that branch on the Linux; merge back to your main line after any compilation problems have been fixed on both platforms.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: