初めに
Components/atomsディレクトリを作成しました。
git pushし複数のPRを経て、ディレクトリ名はatomsではなくAtomsで作成すべきだったことに気づきました。
問題
ローカルのディレクトリ名を変更しコミット。
npm run buildでビルドした際、importのパスが合わずエラー。
どうやらデフォルトだとgit config core.ignorecaseがtrueのため、ファイル名の大文字と小文字の変更コミットはGitに反映されないようです。
core.ignoreCase
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.
解決方法
まずは設定の変更です。
gitのconfig設定にはグローバルとローカルの2種類あり、git config --local --listでローカルのconfig一覧を出力できます。
今後プロジェクトで大文字・小文字の変更を検知する設定にしたい場合は、git config core.ignorecase falseのコマンドで変更できます。(今回だけ対応したいのであれば設定変更は必須ではありません)
$ git config core.ignorecase true # 大文字と小文字を区別しない(デフォルト)
$ git config core.ignorecase false # 大文字と小文字を区別する
そして、既にgit追跡済みのファイルの対応が必要です。
ディレクトリ名の小文字を大文字に変更したのをgit管理に反映させる
ex): components/atoms → Components/Atoms
git rm --cachedを使う
-
1, ファイル名を変更
-
2,
git rm --cachedで古いファイル名を削除 -
3, 変更したファイル名を
git addしgit commitをすると、Gitの追跡しているファイル名が変わります。
mv exampleFile.txt ExampleFile.txt
git rm --cached exampleFile.txt
git add ExampleFile.txt
git commit -m "ファイル名の変更"
これで、ファイルの中身を編集せずにファイル名のみ小文字→大文字の変更をGitに反映させることができました。