阻止 GitHub 将我的 Windows 1252 .txt 文件转换为 UTF-8

T. *_*Tom 5 encoding github utf-8 windows-1252

“我们\xe2\x80\x99已检测到文件编码为ISO-8859-1。当您提交更改时,我们会将其转码为UTF-8”

\n\n

这是当我尝试上传 Windows 1252 .txt 文件时 GitHub 显示的内容。

\n\n

结果:UTF-8 无法识别的所有字符均显示为 \xef\xbf\xbd

\n\n

我的 ATOM 编辑器成功使用 Windows 1252 作为默认值,但暂存更改窗口显示 \xef\xbf\xbd\'s。

\n\n

我怎样才能阻止 GitHub 这样做?

\n

Von*_*onC 1

除了将.gitattributes编码指令设置为 utf-8 之外,您还可以将现有文件转换为 utf-8,如下所示

#!/bin/sh

find . -type f -print | while read f; do
        mv -i "$f" "$f.recode.$$"
        iconv -f iso-8859-1 -t utf-8 < "$f.recode.$$" > "$f"
        rm -f "$f.recode.$$"
done
Run Code Online (Sandbox Code Playgroud)

您可以调整脚本以将其限制为仅文件的子集。
只有通过推送 utf-8 文件,您才能确保在 GitHub 存储库页面中看到正确的字符。