ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

[转]Character encoding for commit messages

2021-10-21 14:00:28  阅读:435  来源: 互联网

标签:en UTF encoding messages Character US commit your


 

原文:https://www.git-tower.com/help/guides/faq-and-tips/faq/encoding/windows

------------

Character encoding for commit messages

Creating Commits

When Git creates and stores a commit, the commit message entered by the user is stored as binary data and there is no conversion between encodings. The encoding of your commit message is determined by the client you are using to compose the commit message.

However, Git stores the name of the commit encoding if the config key "i18n.commitEncoding" is set (and if it's not the default value "utf-8"). You can print its current value with the following command:

$ git config i18n.commitEncoding

If it shows no output, it defaults to "utf-8".

If you commit changes from the command line, this value must match the encoding set in your shell environment. Otherwise, a wrong encoding is stored with the commit and can result in garbled output when viewing the commit history.

Tower uses and enforces UTF-8 as encoding for commits (regardless of what is set for "i18n.commitEncoding") to ensure a valid commit encoding.

On the command line, you can verify your encoding with the following command:

$ locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"

This prints your current character encoding settings. Additionally, when using Terminal, you should make sure that your preferred encoding is correctly set in the preferences as well.
You can set your preferred shell encoding with the following lines in your shell profile:

export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"

Note: You should rather adjust your shell environment to UTF-8 than your Git config - because UTF-8 is the recommended encoding.

Viewing Commit History and Encodings

If you view the commit log on the command line, the config value "i18n.logOutputEncoding" (which defaults to "i18n.commitEncoding") needs to match your shell encoding as well. The command converts messages from the commit encoding to the output encoding. If your shell encoding does not match the output encoding, you will again receive garbled output!

However, if the commit message is stored with the wrong encoding and viewed with the wrong encoding, the commit message will display correctly. While this may look fine on your system, as soon as you share the commits with someone else, she will receive garbled output.

Inspecting Commit Encodings

Once a commit has a wrong encoding, there is no reliable way to detect and fix the encoding when the commit is displayed by clients. If possible, try to recreate the commit with the correct encoding by rebasing it.

If you want to examine a commit and its stored encoding, you can use the following command to inspect it:

$ git log -1 --pretty='format:%h: "%B" (Encoding: "%e")' SHA

You can also override the config value for "i18n.logOutputEncoding" when invoking the command to convert the encoding to the given output:

$ git -c i18n.logOutputEncoding=UTF-8 log -1 --pretty='format:%h: "%B" (Encoding: "%e")' SHA

标签:en,UTF,encoding,messages,Character,US,commit,your
来源: https://www.cnblogs.com/oxspirt/p/15433164.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有