1. 查看当前 git 大小写敏感配置信息

    $ git config --global core.ignorecase
    true

    当前配置信息为:全局大小写不敏感

  2. 项目 A 中文件夹命名为 HomeViews,已经提交到 gitlab 仓库中,由于项目规范化需求,需要将文件夹采用小驼峰命名为 homeViews,现在我们修改文件夹名称为 homeViews 后查看分支状态:

    我们发现虽然修改了文件夹名称的大小写,但是由于 git 对大小写不敏感的配置,导致无法发现差异

    $ git status
    On branch master
    Your branch is up to date with 'origin/master'.
    
    nothing to commit, working tree clean
  3. 配置 git 全局大小写敏感。此时 git status 仍然无法监听到文件夹名称大小写的变动

    $ git config --global core.ignorecase false
    
    $ git config --global core.ignorecase
    false
  4. 使用 mv 命令进行重命名, Git尝试重命名文件夹的名称仅更改大小写,但操作系统不允许直接修改大小写

    $ git mv src/HomeViews src/homeViews
    fatal: renaming 'src/HomeViews' failed: Invalid argument
  5. 采取重命名为其它临时名称的方式进行修改

    $ git mv src/HomeViews src/homeViewsTemp
    $ git status
    On branch master
    Your branch is up to date with 'origin/master'.
    
    Changes to be committed:
      (use "git restore --staged <file>..." to unstage)
            renamed:    src/HomeViews/HomePage.txt -> src/homeViewsTemp/HomePage.txt
    $ git mv src/homeViewsTemp src/homeViews
    $ git status
    On branch master
    Your branch is up to date with 'origin/master'.
    
    Changes to be committed:
      (use "git restore --staged <file>..." to unstage)
            renamed:    src/HomeViews/HomePage.txt -> src/homeViews/HomePage.txt
    $ git commit -m "Rename HomeViews to homeViews"
    [master 922ef05] Rename HomeViews to homeViews
     1 file changed, 0 insertions(+), 0 deletions(-)
     rename src/{HomeViews => homeViews}/HomePage.txt (100%)
    $ git push
    Enumerating objects: 5, done.
    Counting objects: 100% (5/5), done.
    Delta compression using up to 12 threads
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 325 bytes | 325.00 KiB/s, done.
    Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    To https://git.henau.edu.cn/leesong/testproject.git
       c2cbbf3..922ef05  master -> master
  6. 此时在远程仓库可以看到名称已修改

    请输入图片描述

最后修改:2024 年 08 月 12 日
如果觉得我的文章对你有用,请随意赞赏