Changing capitalization of filenames in Git

前端 未结 9 1617
孤独总比滥情好
孤独总比滥情好 2020-11-22 14:02

I am trying to rename a file to have different capitalization from what it had before:

git mv src/collision/b2AABB.js src/collision/B2AABB.js
fatal: destinat         


        
相关标签:
9条回答
  • 2020-11-22 14:10

    Considering larsks' answer, you can get it working with a single command with "--force":

     git mv --force myfile MyFile
    
    0 讨论(0)
  • 2020-11-22 14:15

    Sometimes you want to change the capitalization of a lot of file names on a case insensitive filesystem (e.g. on OS X or Windows). Doing git mv commands will tire quickly. To make things a bit easier this is what I do:

    1. Move all files outside of the directory to, let’s, say the desktop.
    2. Do a git add . -A to remove all files.
    3. Rename all files on the desktop to the proper capitalization.
    4. Move all the files back to the original directory.
    5. Do a git add .. Git should see that the files are renamed.

    Now you can make a commit saying you have changed the file name capitalization.

    0 讨论(0)
  • 2020-11-22 14:15

    You can open the ".git" directory and then edit the "config" file. Under "[core]" set, set "ignorecase = true" and you are done ;)

    0 讨论(0)
  • 2020-11-22 14:20

    To bulk git mv files to lowercase on macOS:

    for f in *; do git mv "$f" "`echo $f | tr "[:upper:]" "[:lower:]"`"; done
    

    It will lowercase all files in a folder.

    0 讨论(0)
  • 2020-11-22 14:27

    Set ignorecase to false in git config

    As the original post is about "Changing capitalization of filenames in Git":

    If you are trying to change capitalisation of a filename in your project, you do not need to force rename it from Git. IMO, I would rather change the capitalisation from my IDE/editor and make sure that I configure Git properly to pick up the renaming.

    By default, a Git template is set to ignore case (Git case insensitive). To verify you have the default template, use --get to retrieve the value for a specified key. Use --local and --global to indicate to Git whether to pick up a configuration key-value from your local Git repository configuration or global one. As an example, if you want to lookup your global key core.ignorecase:

    git config --global --get core.ignorecase
    

    If this returns true, make sure to set it as:

    git config --global core.ignorecase false
    

    (Make sure you have proper permissions to change global.) And there you have it; now your Git installation would not ignore capitalisations and treat them as changes.

    As a suggestion, if you are working on multi-language projects and you feel not all projects should be treated as case-sensitive by Git, just update the local core.ignorecase file.

    0 讨论(0)
  • 2020-11-22 14:27

    Working example:

    git mv ./src/images/poster_video.PNG ./src/images/poster_video.png
    
    0 讨论(0)
提交回复
热议问题