你看到的乱码是因为 fc.exe 是很老的 Windows 工具,它根本不真正支持 UTF‑8。它只会把文本当成:单字节“ANSI”(当前系统代码页)或带 BOM 的 UTF‑16(配合 /u)。UTF‑8 文件(尤其无 BOM)被它按单字节拆开,多字节中文序列被误解,再按代码页显示,就成了截图里的乱符。chcp 65001 或勾选“测试版:使用 Unicode UTF‑8 提供全球语言支持”只是在改变显示所用的代码页,并不能让 fc 学会解析 UTF‑8。
解决思路两条:
- 还想用
fc:先把两个文件转成带 BOM 的 UTF‑16 LE,再用fc /u。(Get-Content compare.txt -Raw) | Set-Content compare_utf16.txt -Encoding Unicode (Get-Content standard.txt -Raw) | Set-Content standard_utf16.txt -Encoding Unicode fc /u compare_utf16.txt standard_utf16.txt - 更长远:换支持 UTF‑8 的 diff 工具,例如:
- Git:
git diff --no-index compare.txt standard.txt - WSL:
diff -u compare.txt standard.txt - PowerShell:
Compare-Object (Get-Content compare.txt -Encoding utf8) (Get-Content standard.txt -Encoding utf8) - 或 WinMerge / Beyond Compare / VS Code 等图形工具。
- Git: