現象
創建一個 git 倉庫 git-test
,並提交一個文件 test.go
,然後修改文件名的大小寫爲 Test.go
。
$ mkdir git-test
$ cd git-test
$ git init --initial-branch=main
$ touch test.go
$ git add .
$ git commit -m "feat: add test.go"
$ mv test.go Test.go
$ ls
Test.go
$ git status
On branch main
nothing to commit, working tree clean
可以看到 git status
沒有發生改變,也就是說本地修改的文件名沒有在 git 生效。
解決方法
- 移除本地緩存
$ git rm -r --cached test.go
rm 'test.go'
$ git status
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
deleted: test.go
Untracked files:
(use "git add <file>..." to include in what will be committed)
Test.go
- 配置 git 區分大小寫
$ git config core.ignorecase false
$ git add .
$ git status
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
renamed: test.go -> Test.go
$ git commit -m "refactor: rename test.go"
$ git log
commit 8828b606ebc810bf8510487391cdeff4b86027ee (HEAD -> main)
Author: CatchZeng <[email protected]>
Date: Fri Jun 17 15:59:53 2022 +0800
refactor: rename test.go
commit d8d4b8716c2000bb2dfec2b6bf873887de76d590
Author: CatchZeng <[email protected]>
Date: Fri Jun 17 15:43:07 2022 +0800
feat: add test.go
(END)