什么会导致 git 弄乱字符编码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10623498/
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:55:24  来源:igfitidea点击:

What can cause git to mess with character encoding?

gitencodingcharacter-encodinggit-svngit-extensions

提问by Samuel Rossille

Edit:git does not mess with character encoding. This is still here to share knowlege and avoid others making the same mistake.

编辑:git 不会混淆字符编码。这仍然是为了分享知识并避免其他人犯同样的错误。



The context: My enterprise uses an svn repository. I'm using git-svn as a client to interact with this repository. All text files in the project are (and must be) encoded with windows default encoding (cp-....). I use git-extensions, and sometimes the command line to pilot git.

上下文:我的企业使用 svn 存储库。我使用 git-svn 作为客户端来与这个存储库进行交互。项目中的所有文本文件都(并且必须)使用 Windows 默认编码 (cp-....) 进行编码。我使用 git-extensions,有时使用命令行来引导 git。

What I did: During the last 3 days, I was working on a new feature, and I did a number of local commits. Finally i squashed all these commits into a single one using an interactive rebase, then i used git svn dcommit to push everything on the svn repository in a single commit.

我做了什么:在过去的 3 天里,我正在开发一个新功能,我做了一些本地提交。最后,我使用交互式 rebase 将所有这些提交压缩为一个,然后我使用 git svn dcommit 在单个提交中推送 svn 存储库中的所有内容。

What happened then: A collegue told me that all accents were messed up in the files that I modified, and in the new files after my commit. I had already commited text files with accents in the same repository with my installation of git + svn before, and it's the first time I face this issue.

然后发生了什么:一位同事告诉我,我修改的文件和提交后的新文件中的所有重音都搞砸了。我之前在安装 git + svn 时已经在同一个存储库中提交了带有重音符号的文本文件,这是我第一次遇到这个问题。

My investigation:I did the following things to investigate: opened the files with notepad++, and tried the most current encodings (including windows default and UTF-8) to view them: none of them could display accents properly, and different accents are always rendered by the same sequence of strange glyphs.

我的调查:我做了以下事情来调查:用记事本++打开文件,并尝试使用最新的编码(包括windows默认和UTF-8)来查看它们:它们都不能正确显示重音,并且总是呈现不同的重音由相同的奇怪字形序列。

The temporary workaround:I quickly created a revert commit with git extension and "dcommited" it.

临时解决方法:我快速创建了一个带有 git 扩展名的还原提交并“dcommited”了它。

The question:My enterprise svn repository is OK, but now i have the two following problems to solve:

问题:我的企业 svn 存储库还可以,但现在我有以下两个问题需要解决:

  1. Understand what happened with the characters with accents
  2. Retrieve my work from the SVN history and commit it in a proper way (if possible without reviewing manually all the characters with accents)
  1. 了解带有口音的字符发生了什么
  2. 从 SVN 历史记录中检索我的工作并以适当的方式提交(如果可能,无需手动检查所有带重音的字符)

Can anybody provide some clues (i'm rather new to git) ?

任何人都可以提供一些线索(我对 git 比较陌生)?

回答by Samuel Rossille

And now let's reveal the painful truth (painful for my ego, not for git users): I did mess with the accents, not git.

现在让我们揭示一个痛苦的事实(对我的自尊来说是痛苦的,而不是对 git 用户来说):我确实弄乱了口音,而不是 git。

I could have just removed the question which let's wrongly think that git can mess up with accents, but considering the number of upvotes, i think than a lot of people do the same mistake that i did, so I have chosen to answer my own question to establish the truth, and maybe help people in the same case:

我本可以删除让我们错误地认为 git 会弄乱口音的问题,但考虑到赞成票的数量,我认为很多人都犯了和我一样的错误,所以我选择回答我自己的问题确定真相,也许可以帮助遇到相同情况的人:

  1. Git does not touch to characters other than line breaks.
  2. I broke the accents beforecommiting, and i did not noticed it because i did not pay enough attention. To do so, i edited some of the files with eclipse. Eclipse did not recognize the encoding and the accents were all replace by a weird byte sequence on save. That's all.
  1. 除了换行符之外,Git 不涉及字符。
  2. 我在提交之前打破了口音,我没有注意到它,因为我没有足够的关注。为此,我用 eclipse 编辑了一些文件。Eclipse 无法识别编码,并且在保存时所有重音符号都被一个奇怪的字节序列替换。就这样。

Thanks again to Dmitry Pavlenkofor giving me indications on how to investigate this problem.

再次感谢Dmitry Pavlenko为我提供有关如何调查此问题的指示。

+1 to "git reflog"

+1 到“git reflog”

Happy accent fixing ;=)

快乐的口音修复 ;=)