简体   繁体   English

为什么我的代码中的撇号在git / bash中显示为<##>?

[英]Why does this apostrophe in my code show up as a <##> in git/bash?

I have code that looks like this: 我有看起来像这样的代码:

specifies the maximum points’ interval during

(its inside of a comment). (在评论中)。 When I go to git diff in the bash shell provided by Git for Windows, I get this: 当我在Git for Windows提供的bash shell中转到git diff时,得到以下信息:

 specifies the maximum points<92> interval during 

I assume this is an easy question for somebody, and I'm also hoping my text files aren't being encoded in a wonky manner or something. 我认为这对某些人来说是个简单的问题,而且我也希望我的文本文件不会以不可靠的方式进行编码。

From the documentation, I hope this helps: 从文档中,希望对您有所帮助:

Git is to some extent character encoding agnostic. Git在某种程度上与字符编码无关。

The contents of the blob objects are uninterpreted sequences of bytes. Blob对象的内容是未解释的字节序列。 There is no encoding translation at the core level. 核心级别没有编码转换。

Path names are encoded in UTF-8 normalization form C. This applies to tree objects, the index file, ref names, as well as path names in command line arguments, environment variables and config files (.git/config (see git-config[1]), gitignore[5], gitattributes[5] and gitmodules[5]). 路径名以UTF-8规范化形式C编码。这适用于树对象,索引文件,引用名称以及命令行参数,环境变量和配置文件(.git / config(请参阅git-config)中的路径名。 [1]),gitignore [5],gitattributes [5]和gitmodules [5])。

Note that Git at the core level treats path names simply as sequences of non-NUL bytes, there are no path name encoding conversions (except on Mac and Windows). 请注意,核心级别的Git仅将路径名视为非NUL字节序列,没有路径名编码转换(在Mac和Windows上除外)。 Therefore, using non-ASCII path names will mostly work even on platforms and file systems that use legacy extended ASCII encodings. 因此,即使在使用旧版扩展ASCII编码的平台和文件系统上,使用非ASCII路径名也最有效。 However, repositories created on such systems will not work properly on UTF-8-based systems (eg Linux, Mac, Windows) and vice versa. 但是,在此类系统上创建的存储库将无法在基于UTF-8的系统(例如Linux,Mac,Windows)上正常运行,反之亦然。 Additionally, many Git-based tools simply assume path names to be UTF-8 and will fail to display other encodings correctly. 此外,许多基于Git的工具仅假设路径名称为UTF-8,并且将无法正确显示其他编码。

Commit log messages are typically encoded in UTF-8, but other extended ASCII encodings are also supported. 提交日志消息通常以UTF-8编码,但也支持其他扩展ASCII编码。 This includes ISO-8859-x, CP125x and many others, but not UTF-16/32, EBCDIC and CJK multi-byte encodings (GBK, Shift-JIS, Big5, EUC-x, CP9xx etc.). 这包括ISO-8859-x,CP125x和许多其他文件,但不包括UTF-16 / 32,EBCDIC和CJK多字节编码(GBK,Shift-JIS,Big5,EUC-x,CP9xx等)。

Although we encourage that the commit log messages are encoded in UTF-8, both the core and Git Porcelain are designed not to force UTF-8 on projects. 尽管我们鼓励将提交日志消息编码为UTF-8,但核心和Git瓷器的设计都不能在项目上强制使用UTF-8。 If all participants of a particular project find it more convenient to use legacy encodings, Git does not forbid it. 如果特定项目的所有参与者都发现使用遗留编码更方便,则Git不会禁止使用它。 However, there are a few things to keep in mind. 但是,有几件事要牢记。

git commit and git commit-tree issues a warning if the commit log message given to it does not look like a valid UTF-8 string, unless you explicitly say your project uses a legacy encoding. 如果给它的提交日志消息看起来不像是有效的UTF-8字符串,则git commit和git commit-tree会发出警告,除非您明确地说项目使用了旧式编码。 The way to say this is to have i18n.commitencoding in .git/config file, like this: 这样说的方法是在.git / config文件中包含i18n.commitencoding,如下所示:

[i18n] commitencoding = ISO-8859-1 [i18n] commitencoding = ISO-8859-1

Commit objects created with the above setting record the value of i18n.commitencoding in its encoding header. 使用上述设置创建的提交对象将i18n.commitencoding的值记录在其编码头中。 This is to help other people who look at them later. 这是为了帮助以后查看它们的其他人。 Lack of this header implies that the commit log message is encoded in UTF-8. 缺少此标头意味着提交日志消息以UTF-8编码。

git log, git show, git blame and friends look at the encoding header of a commit object, and try to re-code the log message into UTF-8 unless otherwise specified. 除非另有说明,否则git log,git show,git blame和朋友将查看提交对象的编码标头,并尝试将日志消息重新编码为UTF-8。 You can specify the desired output encoding with i18n.logoutputencoding in .git/config file, like this: 您可以在.git / config文件中使用i18n.logoutputencoding指定所需的输出编码,如下所示:

[i18n] logoutputencoding = ISO-8859-1 [i18n] logoutputencoding = ISO-8859-1

If you do not have this configuration variable, the value of i18n.commitencoding is used instead. 如果没有此配置变量,则使用i18n.commitencoding的值。

Note that we deliberately chose not to re-code the commit log message when a commit is made to force UTF-8 at the commit object level, because re-coding to UTF-8 is not necessarily a reversible operation. 请注意,在进行强制在提交对象级别执行UTF-8的提交时,我们故意选择不重新编码提交日志消息,因为重新编码为UTF-8不一定是可逆的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM