Git弄乱了我的文件,在一些地方显示中文字符 [英] Git messed up my files, showing chinese characters in some places

查看:157
本文介绍了Git弄乱了我的文件,在一些地方显示中文字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

免责声明:通过Git,我的意思是'我'搞砸了。

,尽管这会让其他人更加复杂与您的回购。


disclaimer: By Git, I mean 'I' messed up.

Earlier, I wanted git-gui to show me the diff for which it thinks are binary files.

So I made some changes to my .\.gitattributes

*.ini       text
*.inc       text

But it didn't work. Then I made some changes to my .\.git\info\attributes

*.ini       text
*.inc       text
*.inc crlf diff
*.ini crlf diff

and it worked.

But now when I go back to previous commits it messes up...

This is how it should look:

It doesn't happen in all the files. EDIT: It happens only in files that have any special characters in them.

Q: Is it the issue with the commits itself or just some setting?
Q: Can I recover?

解决方案

Your ini files are saved in UTF-16LE, the encoding that Windows misleadingly describes as ‘Unicode’.

Git's default diffing tools don't work on UTF-16, because it's not an ASCII-compatible encoding. This is why git detected the files as binary originally.

LF/CRLF newline conversion is seeing each 0x0A byte as being a newline, and replacing it with 0x0D-0x0A. But, in a UTF-16LE file, a newline is actually signalled by 0x0A-0x00, and replacing that with 0x0D-0x0A-0x00 means that you've got an odd number of bytes, so the alignment of each two-byte code unit in the next line is out of sync. Consequently every other line gets mangled.

Your options are:

  1. Revert the attribute change and let Git handle the files as binary (losing the benefit of diffs).

  2. Save the files in an ASCII-compatible encoding. It looks like your content doesn't actually have any non-ASCII characters in, so hopefully that's not a problem? Normally you would want to save all your files as UTF-8 - this is ASCII-compatible but also allows all Unicode characters to be used. But that depends on whether Rainmeter supports reading INI files encoded like that (probably not).

  3. Configure git to use a different diff tool, though this will make it more complicated for others to work with your repo.

这篇关于Git弄乱了我的文件,在一些地方显示中文字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆