Git 常見問題 - git 文件不區分大小寫問題

原文:https://makeoptim.com/git-faq/git-ignore-case

現象

創建一個 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 生效

解決方法

  1. 移除本地緩存
$ 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
  1. 配置 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)

參考

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章