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

GitCase SensitiveGit CommitGit Config

Git Problem Overview


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 delete the files and upload them again. Is there a way that Git can be case-sensitive when checking for changes in file names? I have not made any changes to the file itself.

Git Solutions


Solution 1 - Git

As long as you're just renaming a file, and not a folder, you can just use git mv:

git mv -f yOuRfIlEnAmE yourfilename

(As of a change in Git 2.0.1, the -f flag in the incantation above is superfluous, but it was needed in older Git versions.)

Solution 2 - Git

Git has a configuration setting that tells it whether to expect a case-sensitive or insensitive file system: core.ignorecase. To tell Git to be case-senstive, simply set this setting to false. (Be careful if you have already pushed the files, then you should first move them given the other answers).

git config core.ignorecase false

Note that setting this option to false on a case-insensitive file system is generally a bad idea. Doing so will lead to weird errors. For example, renaming a file in a way that only changes letter case will cause git to report spurious conflicts or create duplicate files(from Mark Amery's comment).

Documentation

From the git config documentation:

> core.ignorecase > > If true, this option enables various workarounds to enable git to work better on filesystems that are not case sensitive, like FAT. For example, if a directory listing finds makefile when git expects Makefile, git will assume it is really the same file, and continue to remember it as Makefile. > > The default is false, except git-clone(1) or git-init(1) will probe and set core.ignorecase true if appropriate when the repository is created.

Case-insensitive file-systems

The two most popular operating systems that have case-insensitive file systems that I know of are

  • Windows
  • OS X

Solution 3 - Git

Using SourceTree I was able to do this all from the UI

  1. Rename FILE.ext to whatever.ext
  2. Stage that file
  3. Now rename whatever.ext to file.ext
  4. Stage that file again

It's a bit tedious, but if you only need to do it to a few files it's pretty quick

Solution 4 - Git

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.

Solution 5 - Git

I used those following steps:

git rm -r --cached .
git add --all .
git commit -a -m "Versioning untracked files"
git push origin master

For me is a simple solution

Solution 6 - Git

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.

Solution 7 - Git

We can use git mv command. Example below , if we renamed file abcDEF.js to abcdef.js then we can run the following command from terminal

git mv -f .\abcDEF.js  .\abcdef.js

Solution 8 - Git

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

Solution 9 - Git

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

Solution 10 - Git

  1. rename file Name.jpg to name1.jpg

  2. commit removed file Name.jpg

  3. rename file name1.jpg to name.jpg

  4. amend added file name.jpg to previous commit

    git add name.jpg
    git commit --amend
    

Solution 11 - Git

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

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

Solution 12 - Git

With the following command:

git config --global  core.ignorecase false

You can globally config your git system to be case sensitive for file and folder names.

Solution 13 - Git

Mac OSX High Sierra 10.13 fixes this somewhat. Just make a virtual APFS partition for your git projects, by default it has no size limit and takes no space.

  1. In Disk Utility, click the + button while the Container disk is selected
  2. Select APFS (Case-Sensitive) under format
  3. Name it Sensitive
  4. Profit
  5. Optional: Make a folder in Sensitive called git and ln -s /Volumes/Sensitive/git /Users/johndoe/git

Your drive will be in /Volumes/Sensitive/

enter image description here

https://stackoverflow.com/questions/17683458/how-do-i-commit-case-sensitive-only-filename-changes-in-git#comment78880496_26185365

Solution 14 - Git

When you've done a lot of file renaming and some of it are just a change of casing, it's hard to remember which is which. manually "git moving" the file can be quite some work. So what I would do during my filename change tasks are:

  1. remove all non-git files and folder to a different folder/repository.
  2. commit current empty git folder (this will show as all files deleted.)
  3. add all the files back into the original git folder/repository.
  4. commit current non-empty git folder.

This will fix all the case issues without trying to figure out which files or folders you renamed.

Solution 15 - Git

I've faced this issue several times on MacOS. Git is case sensitive but Mac is only case preserving.

Someone commit a file: Foobar.java and after a few days decides to rename it to FooBar.java. When you pull the latest code it fails with The following untracked working tree files would be overwritten by checkout...

The only reliable way that I've seen that fixes this is:

  1. git rm Foobar.java
  2. Commit it with a message that you cannot miss git commit -m 'TEMP COMMIT!!'
  3. Pull
  4. This will pop up a conflict forcing you to merge the conflict - because your change deleted it, but the other change renamed (hence the problem) it
  5. Accept your change which is the 'deletion'
  6. git rebase --continue
  7. Now drop your workaround git rebase -i HEAD~2 and drop the TEMP COMMIT!!
  8. Confirm that the file is now called FooBar.java

Solution 16 - Git

I took @CBarr answer and wrote a Python 3 Script to do it with a list of files:

#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

import os
import shlex
import subprocess

def run_command(absolute_path, command_name):
    print( "Running", command_name, absolute_path )

    command = shlex.split( command_name )
    command_line_interface = subprocess.Popen( 
          command, stdout=subprocess.PIPE, cwd=absolute_path )

    output = command_line_interface.communicate()[0]
    print( output )

    if command_line_interface.returncode != 0:
        raise RuntimeError( "A process exited with the error '%s'..." % ( 
              command_line_interface.returncode ) )

def main():
    FILENAMES_MAPPING = \
    [
        (r"F:\\SublimeText\\Data", r"README.MD", r"README.md"),
        (r"F:\\SublimeText\\Data\\Packages\\Alignment", r"readme.md", r"README.md"),
        (r"F:\\SublimeText\\Data\\Packages\\AmxxEditor", r"README.MD", r"README.md"),
    ]

    for absolute_path, oldname, newname in FILENAMES_MAPPING:
        run_command( absolute_path, "git mv '%s' '%s1'" % ( oldname, newname ) )
        run_command( absolute_path, "git add '%s1'" % ( newname ) )
        run_command( absolute_path, 
             "git commit -m 'Normalized the \'%s\' with case-sensitive name'" % (
              newname ) )

        run_command( absolute_path, "git mv '%s1' '%s'" % ( newname, newname ) )
        run_command( absolute_path, "git add '%s'" % ( newname ) )
        run_command( absolute_path, "git commit --amend --no-edit" )

if __name__ == "__main__":
    main()

Solution 17 - Git

If nothing worked use git rm filename to delete file from disk and add it back.

Solution 18 - Git

so there are many solutions to this case sensitivity deployment problem with how GitHub handles it.

In my case, I had changed the filename casing convention from uppercase to lowercase.

I do believe that git can track the change but this command git config core.ignorecase false dictates how git operates behind the scenes

In my case, I ran the command and git suddenly had lots of files to track labeled untracked.

I then hit git add. , then git committed and ran my build on netlify one more time.

Then all errors now displayed could be traced e.g Module not found: Can't resolve './Components/ProductRightSide' in '/opt/build/repo/components/products and fixed such that git was able to track and implement the changes successfully.

It's quite a workaround and a fingernail away from frustration but trust me this will surely work.

PS: after fixing your issue you may want to run the command git config core.ignorecase true to restore how git works with case sensitivity.

Also, note git config core.ignorecase false has issues with other filename extensions so you may want to watch out, do it if you know what you’re doing and are sure of it.

Here's a thread on netlify that can help out, possibly

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGil ShulmanView Question on Stackoverflow
Solution 1 - GitKeith SmileyView Answer on Stackoverflow
Solution 2 - Gituser456814View Answer on Stackoverflow
Solution 3 - GitFiniteLooperView Answer on Stackoverflow
Solution 4 - GitSijmen MulderView Answer on Stackoverflow
Solution 5 - GitandrewvergelView Answer on Stackoverflow
Solution 6 - GitSteve ChambersView Answer on Stackoverflow
Solution 7 - Gituser4987870View Answer on Stackoverflow
Solution 8 - Gituser1821510View Answer on Stackoverflow
Solution 9 - GitAnupamView Answer on Stackoverflow
Solution 10 - GitrazonView Answer on Stackoverflow
Solution 11 - Gituser110857View Answer on Stackoverflow
Solution 12 - GitAmerllicAView Answer on Stackoverflow
Solution 13 - GitRay FossView Answer on Stackoverflow
Solution 14 - GitRicardo Virtudazo JrView Answer on Stackoverflow
Solution 15 - GitAshwin JayaprakashView Answer on Stackoverflow
Solution 16 - GituserView Answer on Stackoverflow
Solution 17 - Gitgopal PandeyView Answer on Stackoverflow
Solution 18 - GitThink DigitalView Answer on Stackoverflow