How do I commit case-sensitive only filename changes in Git?

前端 未结 16 2309
我在风中等你
我在风中等你 2020-11-22 03:31

I have changed a few files name by de-capitalize the first letter, as in Name.jpg to name.jpg. Git does not recognize this changes and I had to de

相关标签:
16条回答
  • 2020-11-22 03:59

    This is what I did on OS X:

    git mv File file.tmp
    git mv file.tmp file
    

    Two steps because otherwise I got a “file exists” error. Perhaps it can be done in one step by adding --cached or such.

    0 讨论(0)
  • 2020-11-22 04:00

    You can use git mv:

    git mv -f OldFileNameCase newfilenamecase
    
    0 讨论(0)
  • 2020-11-22 04:01

    Under OSX, to avoid this issue and avoid other problems with developing on a case-insensitive filesystem, you can use Disk Utility to create a case sensitive virtual drive / disk image.

    Run disk utility, create new disk image, and use the following settings (or change as you like, but keep it case sensitive):

    Mac Disk Utility Screenshot

    Make sure to tell git it is now on a case sensitive FS:

    git config core.ignorecase false
    
    0 讨论(0)
  • 2020-11-22 04:03

    Similar to @Sijmen's answer, this is what worked for me on OSX when renaming a directory (inspired by this answer from another post):

    git mv CSS CSS2
    git mv CSS2 css
    

    Simply doing git mv CSS css gave the invalid argument error: fatal: renaming '/static/CSS' failed: Invalid argument perhaps because OSX's file system is case insensitive

    p.s BTW if you are using Django, collectstatic also wouldn't recognize the case difference and you'd have to do the above, manually, in the static root directory as well

    0 讨论(0)
  • 2020-11-22 04:04

    I tried the following solutions from the other answers and they didn't work:

    • git mv filename
    • git rm -f filename

    If your repository is hosted remotely (GitHub, GitLab, BitBucket), you can rename the file on origin (GitHub.com) and force the file rename in a top-down manner.

    The instructions below pertain to GitHub, however the general idea behind them should apply to any remote repository-hosting platform. Keep in mind the type of file you're attempting to rename matters, that is, whether it's a file type that GitHub deems as editable (code, text, etc) or uneditable (image, binary, etc) within the browser.

    1. Visit GitHub.com
    2. Navigate to your repository on GitHub.com and select the branch you're working in
    3. Using the site's file navigation tool, navigate to the file you intend to rename
    4. Does GitHub allow you to edit the file within the browser?
      • a.) Editable
        1. Click the "Edit this file" icon (it looks like a pencil)
        2. Change the filename in the filename text input
      • b.) Uneditable
        1. Open the "Download" button in a new tab and save the file to your computer
        2. Rename the downloaded file
        3. In the previous tab on GitHub.com, click the "Delete this file" icon (it looks like a trashcan)
        4. Ensure the "Commit directly to the branchname branch" radio button is selected and click the "Commit changes" button
        5. Within the same directory on GitHub.com, click the "Upload files" button
        6. Upload the renamed file from your computer
    5. Ensure the "Commit directly to the branchname branch" radio button is selected and click the "Commit changes" button
    6. Locally, checkout/fetch/pull the branch
    7. Done
    0 讨论(0)
  • 2020-11-22 04:08

    Sometimes it is useful to temporarily change Git's case sensitivity.

    Method #1 - Change case sensitivity for a single command:

    git -c core.ignorecase=true checkout mybranch to turn off case-sensitivity for a single checkout command. Or more generally: git -c core.ignorecase= <<true or false>> <<command>>. (Credit to VonC for suggesting this in the comments.)

    Method #2 - Change case sensitivity for multiple commands:

    To change the setting for longer (e.g. if multiple commands need to be run before changing it back):

    1. git config core.ignorecase (this returns the current setting, e.g. false).
    2. git config core.ignorecase <<true or false>> - set the desired new setting.
    3. ...Run multiple other commands...
    4. git config core.ignorecase <<false or true>> - set config value back to its previous setting.
    0 讨论(0)
提交回复
热议问题