15

On my Windows box, I tried to create a Subversion patch by using the command svn diff > my_patch.diff. The resulting file was encoded with UTF-16, rather than UTF-8 or ASCII, so when I tried to use patch (from GnuWin32) to apply the patch, it didn't work.

I was able to convert the patch file to UTF8 by opening it in Notepad and saving as the desired format, and patch handled it fine after that. But, is there a way to get svn diff to generate UTF8 on Windows?


Update: As my answer indicates, it turns out that the problem is really unrelated to Subversion, diff, or patch. It was PowerShell that was oh-so-helpfully converting the output to Unicode. I'm leaving the question as-is so that someone with a similar problem might stumble upon it.

Kristopher Johnson
  • 81,409
  • 55
  • 245
  • 302
  • In linux flavors, a `--diff-cmd` can be given, is that also the case for the windows command line variant? – Wrikken Jul 19 '10 at 14:49
  • `--diff-cmd` is supported. What should I use as the argument? – Kristopher Johnson Jul 19 '10 at 15:56
  • 2
    Side note: Subversion doesn't like UTF-16 or UTF-32. It will always treat them as binary files and therefore `svn diff` doesn't even work on them (braindead but still no fix). So, there (currently) can't be a way that `svn di` Unicode in anything else than UTF-8. – Joey Jul 20 '10 at 07:40
  • I ran into this exact issue. Thank you! The most frustrating part was svn patch did not report any kind of error; just executed with no output and no change to the files. – Allen Oliver Nov 09 '17 at 21:57

1 Answers1

19

After much head-scratching and experimenting with different diff utilities, I figured this out:

I was running my svn diff in a PowerShell command window. PowerShell's output redirection operators convert the output to Unicode.

If I run svn diff > my_patch.diff in a cmd.exe shell, then everything works fine.

To make this work in PowerShell, one must use a command like this:

svn diff | out-file -encoding ascii my_patch.diff

I'm sure there is somebody at Microsoft who thinks this behavior is really awesome.

Kristopher Johnson
  • 81,409
  • 55
  • 245
  • 302