如何防止“svn diff”来自在 Windows 上生成 Unicode 输出
在我的 Windows 机器上,我尝试使用命令 svn diff > 创建 Subversion 补丁; my_patch.diff
。生成的文件是用 UTF-16 编码的,而不是 UTF-8 或 ASCII,因此当我尝试使用 patch
(来自 GnuWin32) 来应用补丁,但没有成功。
我能够通过在记事本中打开补丁文件并将其保存为所需的格式来将其转换为 UTF8,之后 patch
处理得很好。但是,有没有办法让 svn diff 在 Windows 上生成 UTF8 呢?
更新:正如我的回答所示,事实证明该问题实际上与 Subversion、diff
或 patch
无关。 PowerShell 非常有帮助地将输出转换为 Unicode。我将问题按原样保留,以便有类似问题的人可能会偶然发现它。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过多次绞尽脑汁并尝试不同的
diff
实用程序后,我发现了这一点:我是在 PowerShell 命令窗口中运行我的
svn diff
。 PowerShell 的输出重定向运算符将输出转换为Unicode。如果我运行 svn diff > my_patch.diff 在
cmd.exe
shell 中,然后一切正常。要在 PowerShell 中实现此功能,必须使用如下命令:
我确信 Microsoft 中有人认为这种行为真的很棒。
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 acmd.exe
shell, then everything works fine.To make this work in PowerShell, one must use a command like this:
I'm sure there is somebody at Microsoft who thinks this behavior is really awesome.