2

I face a problem as below. Please give me a solution. Thanks in advance!

I use Linux OS (ubuntu)

Initially, I checkout new branch with the file test.properties file encoding:

test.properties: text/plain; charset=unknown-8bit

Intellij Seting file encoding: enter image description here

on Browser, the text show like:

# 基本情報

I only add '#' character for one line, then I commit file, push my_branch to my repository I run git diff command:

git diff
    -# <8A><EE><96>{<8F><EE><95><F1>
    +## \u57FA\u672C\u60C5\u5831

.... other lines are also changed into UTF-8 encoding.

How can I prevent the problem? Simply, It just marks as below: My expectation looks like this:

-# <8A><EE><96>{<8F><EE><95><F1>
+## <8A><EE><96>{<8F><EE><95><F1>
A.H.
  • 63,967
  • 15
  • 92
  • 126
Mr Special
  • 1,576
  • 1
  • 20
  • 33
  • Could it be merely a matter of representation in the diff interface? Is the file coding really changed? – matt Nov 15 '18 at 03:52
  • @matt the file is also changed, when I open the file via browser. on browser, it shows ## \u57FA\u672C\u60C5\u5831 instead of ## 基本情報 But, on IDE: it shows: ## 基本情報 – Mr Special Nov 15 '18 at 03:55
  • First, read https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/ - then realize that Git itself doesn't even *look* at encoding, it just compares byte-strings. It leaves "encoding" up to *other* software. You need to convince the other software to deal with encoding in a way that behaves well for *you;* and Git is only going to deal with bytes. – torek Nov 15 '18 at 06:42
  • (Git does make one concession to encoding: it will, if you tell it to, put an `encoding` header into a commit, to help other software decide how to treat the bytes in the commit log text.) Also, the reason these are comments is: it looks like IntelliJ *does* try to understand encodings, so maybe that's where to fiddle with this. But I know nothing about IntelliJ; this question is posted to [tag:git] and [tag:gitlab], not [tag:intellij-idea], at least at the moment. – torek Nov 15 '18 at 06:42
  • @torek thanks your response. How can I put an encoding header into a commit ? – Mr Special Nov 15 '18 at 07:05
  • Set `i18n.commitencoding` in your git configuration (`git config i18n.commitencoding `). See also the description of `i18n.logOutputEncoding` in [the `git commit` documentation](https://www.kernel.org/pub/software/scm/git/docs/git-commit.html). Note that use of these settings is discouraged—if you can get `LANG=` to work for you on Linux, for instance, that's the way to go. – torek Nov 15 '18 at 07:16

1 Answers1

2

I've found out the cause. It comes from changing setting from IDE.

I unchecked Transparent native-to-ascii conversion as below: enter image description here

Ok, now the merge request only showed what was changed.

Mr Special
  • 1,576
  • 1
  • 20
  • 33