Closed pzhlkj6612 closed 1 year ago
You can enable VSCode [Auto guess encoding] to avoid this. Hope it can help.
adfc1c714b73fd6b4f0a4a025f362a2305e7c205 fixed this issue, now the output of "git-diff" looks fine: adfc1c714b73fd6b4f0a4a025f362a2305e7c205 修复了这个问题,现在“git-diff”的输出看起来没问题了:
$ git diff --unified=0 -- sfud/src/sfud_sfdp.c
diff --git a/sfud/src/sfud_sfdp.c b/sfud/src/sfud_sfdp.c
index 0564f12..e19b4ac 100644
--- a/sfud/src/sfud_sfdp.c
+++ b/sfud/src/sfud_sfdp.c
@@ -226 +226 @@ static bool read_basic_table(sfud_flash *flash, sfdp_para_header *basic_header)
- //TODO 目前为 1.0 所提供的方式,后期支持 V1.5 及以上的方式读取 page size
+ //TODO 目前为 1.0 所提供的方式,后期支持 V1.5 及以上的方式读取 page size 中文Chinese中文
Background | 背景
Some editors automatically chose the "UTF-8" encoding when opening the "sfud/src/sfud_sfdp.c" file. In VS Code, we can see the following on line 226 of this file: 一些编辑器自动选择“UTF-8”编码来打开“sfud/src/sfud_sfdp.c”。在 VS Code 中,我们能在这个文件的第226行看到如下内容:
I guess the garbled text is Chinese, so I tried to reopen the file with the "GB 2312" encoding: 我猜这些乱码实际上是中文文本,因此试着用“GB 2312”编码重新打开了这个文件:
Now it's readable. 现在这些内容是可读的了。
Since modern frontend frameworks and web browsers are smart enough, we don't seem to be bothered by encoding issue on GitHub: 由于现代的前端框架与浏览器足够智能,在 GitHub 上我们似乎不会被编码所困扰:
https://github.com/armink/SFUD/blob/09911665bbcc90e4fb7b96a0ac0ee6bd483be220/sfud/src/sfud_sfdp.c#L226
Problem | 问题
Let's make some changes in "sfud/src/sfud_sfdp.c". Open the file with "GB 2312" in VS Code and add some characters like this: 在“sfud/src/sfud_sfdp.c”里做些修改吧。以“GB 2312”编码打开它并添加一些字符:
Then, call "git diff": 接着执行“git diff”:
Well, these characters represented in hexadecimal are not what we expect. How to make the file encoding correctly recognized by Git? 呃,我们并不需要这些十六进制形式的字符。那么如何让 Git 正确识别文件的编码呢?
After some searching, I've found two solutions: 经过搜索,我找到了两种方法:
working-tree-encoding=gb2312
to ".gitattributes" to make Git process source code files with the "GB 2312" encoding; | 向“.gitattributes”添加working-tree-encoding=gb2312
使 Git 以“GB 2312”编码处理源代码文件;Reference | 参考