I Don’t Git Case Sensitivity

Git is great! Even though it’s totally (hashtag) awesome sauce, you can encounter the occasional strangeness from time to time. My encounter deals with case sensitivity with both file names and also directory names.

I was given a directory that contained sub-directories for imagery we were using with a project. Without thinking I placed the folder into my project and went on my merry way. The problem though was that each of these sub-directories (4 in my case) had a capital letter and I was referencing them in my markup and stylesheet as a lowercase reference. So if the directory was named “Fake” I would place in my CSS url(../fake/img.jpg). This works locally, but when I push to our dev server (Centos) the paths to assets break because our naming conventions don’t match (fakedir doesn’t match Fakedir). When u make a new commit Git still tracks the directory with a capital letter even though you’ve changed it to lowercase locally on your machine. Git does not “Git” it.

So what can we do to fix this? We’ll need to move and rename to an intermediate name and then name it back to the original name like the example below (we’re taking a directory named “Test” and renaming it to “test”):

grayghostvisuals ✭ GrayGhostVisualsMacBookAir.local  ~/Sites/Practice-Git on master
$ g mv Test/ test2
grayghostvisuals ✭ GrayGhostVisualsMacBookAir.local  ~/Sites/Practice-Git on master*
$ g mv test2/ test
grayghostvisuals ✭ GrayGhostVisualsMacBookAir.local  ~/Sites/Practice-Git on master*
$ gs
On branch master
Your branch is up-to-date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD ..." to unstage)

	renamed:    Test/File.txt -> test/File.txt

If your gut is telling you this is a really long way to do things then I would tell you that your gut is right. What I had help discovering was that in OS X, folder === Folder, so if you move, Git won’t see any difference. You have to explicitly tell Git about the move requiring the temporary name you see (test2) in the bash commands above.

The quicker way is to manually remove all the directories from the local copy, commit and push this removal to your remote repo (i.e Github) then place these directories back into your local copy and rename the directories to lowercase. Not the best solution, but it’s more efficient than doing the commands listed above.

Whoever thought a case insensitive file system was a good idea probably should rethink things.

GrayGhost

Web Development & Design, Technical Writing, Interaction Design, Open Source Maker & Contributor. Helping Create A Better Web. http://grayghostvisuals.com.
  1. It’s much easier to

    git mv -f someName.jpg somename.jpg
  2. ❧ Pawel shouted:
    2014/09/12 • 1:09 am

    Mac OS Extended (Journaled, Case-Sensitive) aka HFSX is an extension to HFS Plus and allows volumes to have case-sensitive file and directory names.

    A case-sensitive volume is supported as a start volume format. An HFSX file system for Mac OS X Server must be specifically selected when erasing a volume and preparing a disk before initial installation.

    https://support.apple.com/kb/PH8289

  3. You have to set the core.ignorecase config to false to not ignore it :

    git config core.ignorecase false
  4. ❧ Phil W shouted:
    2020/07/05 • 6:19 pm

    MacOS isn’t the only file system to ignore case… Windows doesn’t care either and you have to adopt the same approaches outlined here to resolve.

    It is also worth noting that URLs should also be case insensitive though many servers only support case insensitivity in parts of the URL.

Leave a Reply

Your email address will not be published. Required fields are marked *

show formatting examples
<pre class="language-[markup | sass | css | php | javascript | ruby | clike | bash]"><code>
…code example goes here…
</code></pre>

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Comment Preview

  1. John Doe shouted this comment preview:
    2014/01/08