How to Prevent "svn diff" from Generating Unicode Output on Windows
On my Windows box, I tried to create a Subversion patch by using the comma开发者_JS百科nd 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.
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.
精彩评论