LoginSignup
27
15

Git でファイル名の大文字小文字の変更が検出されない

Posted at

表題の件、年に1回あるかないかくらいのペースで毎回ハマって調べているので自分でも記事にまとめて知識の定着化を狙います。

起こった現象

git で管理しているファイル名を次のような大文字/小文字のみの変更を行った場合に、git ではファイル名の変化が検知できませんでした。

例)Kitkat.cs => KitKat.cs (太字部分が、小文字のkから大文字のKに変更されています。)

これは core.ignorecasetrue のときに発生します。

If true, this option enables various workarounds to enable Git to work better on filesystems that are not case sensitive, like FAT. For example, if a directory listing finds "makefile" when Git expects "Makefile", Git will assume it is really the same file, and continue to remember it as "Makefile".
The default is false, except git-clone[1] or git-init[1] will probe and set core.ignoreCase true if appropriate when the repository is created.

上記引用部分をDeepLで翻訳した結果
image.png

なるほどです。たしかに Makefile は大文字/小文字関係なく同じファイルと認識して欲しいケースな気がします。(Makefile を扱ったことがないので適当に言っています。)

対策

  1. git mv でファイル名をリネームする
  2. core.ignorecase false にする

git mv でファイル名をリネームする

私はこちらで対応しました。

 git mv ./Kitkat.cs ./KitKat.cs

core.ignorecase false にする

git config core.ignorecase false

こちらの対応をする場合は注意が必要そうです。もともと true で成立していた作りが壊れる可能性があるかもしれません。
ちなみにこれを私が参加しているプロジェクトで行うと、今までは大文字/小文字が区別なく同一ファイルとしてみなされていたファイルが、ファイル名が変わったと認識されて git の変化点として出現してきました。

メリットとデメリットを把握したうえで設定が必要そうです。

参考にした記事

27
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
15