git GitHub:对文件使用 UTF-8 编码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8038729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:09:03  来源:igfitidea点击:

GitHub: Using UTF-8 encoding for files

gitencodinggithub

提问by Seb Nilsson

Why isn't UTF-8 the default encoding for GitHub?

为什么 UTF-8 不是 GitHub 的默认编码?

Does that mean that there are any drawbacks to change from the default "cp1252"?

这是否意味着从默认的 "cp1252" 更改任何缺点

Does it have anything to do with using GitHub across platforms between Windows and Mac OSX?

它与在 Windows 和 Mac OSX 之间跨平台使用 GitHub 有什么关系吗?

The question is asked from using GitHub, but can be asked about Git in general.

该问题是通过使用 GitHub 提出的,但一般可以询问Git

I'm mostly doing development in .NET, HTML5 and Javascript, if that matters in the subject.

我主要使用 .NET、HTML5 和 Javascript 进行开发,如果这对主题很重要的话。

回答by Michael Borgwardt

Wild guess: are you using TortoiseGit? Is that were you're seeing a default encoding set to cp1252?

疯狂的猜测:你在使用 TortoiseGit 吗?那是您看到的默认编码设置为 cp1252 吗?

If so, it's simply TortoiseGit using the default encoding of your Windows installation.

如果是这样,它只是使用 Windows 安装的默认编码的 TortoiseGit。

Edit:Exactly the same is true for the Git GUI

编辑:Git GUI 完全一样

Here's a discussion from a git developer's mailing listgiving an explanation:

这是来自 git 开发人员邮件列表讨论,给出了解释:

  • Make diffs and blame default to the system (locale) encoding instead of hard-coding UTF-8.
  • Add a gui.encoding option to allow overriding it.
  • gitattributes still have the final word.

The rationale for this is Windows support:

  1. Windows people are accustomed to using legacy encodings for text files. For many of them defaulting to utf-8 will be counter-intuitive.
  2. Windows doesn't support utf-8 locales, and switching the system encoding is a real pain. Thus the option.
  • 使差异和归咎默认为系统(语言环境)编码,而不是硬编码 UTF-8。
  • 添加 gui.encoding 选项以允许覆盖它。
  • gitattributes 仍然有最终决定权。

这样做的理由是 Windows 支持:

  1. Windows 人员习惯于对文本文件使用旧编码。对于他们中的许多人来说,默认为 utf-8 将是违反直觉的。
  2. Windows 不支持 utf-8 语言环境,切换系统编码是一个真正的痛苦。因此选择。