奇特なブログ

「殊勝に値する行いや心掛け」を意味する、奇特な人になる為のブログです

Gitでディレクトリ名を変更してリネームを検知する


$ git status
On branch master
Changes to be committed:
(use "git reset HEAD ..." to unstage)

renamed: a/test.php -> A/test.php

要は、↑の状態を「case-"in"sensitive」でどうやるのかという(笑)
意外と、ググっても出てこなかった(じゃなきゃ書かないが)ですよ。

git version 2.19.0.windows.1の、GitBash上で行っています。


$ ls -al
total 36
drwxr-xr-x 1 ? 197121 0 9月 14 21:56 ./
drwxr-xr-x 1 ? 197121 0 9月 14 21:48 ../
drwxr-xr-x 1 ? 197121 0 9月 14 21:56 .git/
drwxr-xr-x 1 ? 197121 0 9月 14 21:56 a/


$ cp -r a a_


$ git rm -r a
rm 'a/test.php'


$ mv a_ A


$ git add A


$ git status
On branch master
Changes to be committed:
(use "git reset HEAD ..." to unstage)

renamed: a/test.php -> A/test.php

以上。

環境によるのか、「git add A」は、実行しなくても、その前にrenamedになっているケースもありましたね。

case-sensitiveなら、言うまでもなく


$ git mv a A

で終了(笑)
case-insensitiveなOS(というかファイルシステム)なんて無くなれば良いのに(笑)