gitでの日本語ファイル名の文字化け対処
問題
git status, git commit, あるいはVS Codeでのコミットも同じなのだが、日本語のファイル名が文字化けすることがある。それぞれ、サンプル.txt, テスト.txtなのだが、適切に表示されていない。
$ git commit
ブランチ main
Your branch is up to date with 'origin/main'.
追跡されていないファイル:
(use "git add <file>..." to include in what will be committed)
"\343\202\265\343\203\263\343\203\227\343\203\253.txt"
"\343\203\206\343\202\271\343\203\210.txt"
nothing added to commit but untracked files present (use "git add" to track)
$ git status
ブランチ main
Your branch is up to date with 'origin/main'.
追跡されていないファイル:
(use "git add <file>..." to include in what will be committed)
"\343\202\265\343\203\263\343\203\227\343\203\253.txt"
"\343\203\206\343\202\271\343\203\210.txt"
nothing added to commit but untracked files present (use "git add" to track)
解決法
あちこちで以下のコマンドを実行しろと買いてある。
git config --global core.quotepath false
こうすると、~/.gitconfigには以下のように記述される。つまり、直接的にここを編集してもよい。
[core]
quotepath = false
治らない
この解決策では治らなかった。相変わらず文字化けが続く。このリポジトリにおいて、以下のコマンドで設定を確認してみる。
$ git config --list
core.quotepath=false
core.pager=cat
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.quotepath=true
なぜか「core.quotepath=false」の後に、「core.quotepath=true」という行が出現している。このリポジトリのconfigを表示させてみる。
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
quotepath = true
[remote "origin"]
url = https://gitlab.com/jimakudaio_docs/original1
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
merge = refs/heads/main
vscode-merge-base = origin/main
つまり、グローバルには「core.quotepath=false」としたが、このリポジトリのみのローカルでは「core.quotepath=true」としてしまっている。そして、最後に出てきたものが有効、つまり、ローカルに設定されているとそちらが有効になってしまう。
参考:https://qiita.com/shionit/items/fb4a1a30538f8d335b35
完全な解決策
git config --local core.quotepath false
とするか、あるいは、.git/configから当該行を削除してしまうこと。これで以下のように日本語として表示される。
$ git status
ブランチ main
Your branch is up to date with 'origin/main'.
追跡されていないファイル:
(use "git add <file>..." to include in what will be committed)
サンプル.txt
テスト.txt
nothing added to commit but untracked files present (use "git add" to track)
ディスカッション
コメント一覧
まだ、コメントがありません