美文网首页
Git 常见问题 - git 文件不区分大小写问题

Git 常见问题 - git 文件不区分大小写问题

作者: CatchZeng | 来源:发表于2022-06-17 16:13 被阅读0次

    原文: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 <xxxxxxxx@xx.com>
    Date:   Fri Jun 17 15:59:53 2022 +0800
    
        refactor: rename test.go
    
    commit d8d4b8716c2000bb2dfec2b6bf873887de76d590
    Author: CatchZeng <xxxxxxxx@xx.com>
    Date:   Fri Jun 17 15:43:07 2022 +0800
    
        feat: add test.go
    (END)
    

    参考

    相关文章

      网友评论

          本文标题:Git 常见问题 - git 文件不区分大小写问题

          本文链接:https://www.haomeiwen.com/subject/hnkhvrtx.html