ツヨシのブログ

技術的な事とか日常の事とか徒然なるままに

スポンサーリンク

Gitを使用したときに日本語で文字化けを解消する

スポンサーリンク

問題となった事

Gitを使用したときにファイル名が日本語の場合に表示が文字化けしました。さてどうしたものか。

以下の"てすと.txt"とファイル名をつけたファイルのステータスを見てみます。

$ ls -al
total 48
drwxr-xr-x@  5 tsuyoshi  staff    170  2 10 12:02 .
drwx------@ 48 tsuyoshi  staff   1632  2 10 09:20 ..
-rw-r--r--@  1 tsuyoshi  staff   6148  2 10 12:01 .DS_Store
-rw-------@  1 tsuyoshi  staff  12288  9 12 06:58 .test.md.swp
-rw-r--r--@  1 tsuyoshi  staff     10  2 10 12:02 てすと.txt

Gitでステータスを見てみると、

$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   .test.md.swp
    new file:   "\343\201\246\343\201\231\343\201\250.txt"

こんな感じで"テスト.txt"のファイル名が"\343\201\246\343\201\231\343\201\250.txt"と表示されています。 このままだと、このファイル名がわからないですね。

日本語ファイル名を表示できるよいうに設定を変更する

この問題を解決するためにはconfigにより設定を行うことで解決できます。 Gitのcore.quotepathをfalseにします。 コマンドは次のようになります。

$ git config --global core.quotepath false

無事表示できるようになりました。

$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   .test.md.swp
    new file:   てすと.txt

独習Git

独習Git

アリスとボブのGit入門レッスン

アリスとボブのGit入門レッスン