Scott Hanselman

Git is case-sensitive and your filesystem may not be - Weird folder merging on Windows

June 27, '19 Comments [7] Posted in DasBlog | Open Source
Sponsored By

I was working on DasBlog Core (an .NET Core cross-platform update of the ASP.NET WebForms-based blogging software that runs this blog) with Mark Downie, the new project manager, and Shayne Boyer. This is part of a larger cloud re-architecture of hanselman.com and the systems that run this whole site.

Shayne was working on getting a DasBlog Core CI/CD (Continuous Integration/Continuous Development) running in Azure DevOps' build system. We wanted individual build pipelines to confirm that DasBlog Core was in fact, cross-platform, so we needed to build, test, and run it on Windows, Linux, and Mac.

The build was working great on Windows and Mac...but failing on Linux. Why?

Well, like all things, it's complex.

  • Windows has a case-insensitive file system.
  • By default, Mac uses a case-insensitive file system.

Since Git 1.5ish there's been a setting

git config --global core.ignorecase true

but you should always be aware of what a setting does before you just set it.

If you're not careful, you or someone on your team can create a case sensitive file path in your git index while you're using a case insensitive operating system like Windows or Mac. If you do this, you'll be able to end up with two separate entries from git's perspective. However Windows will silently merge them and see just one.

Here's our themes folder structure as seen on GitHub.com.

Case insenstive folder names

But when we clone it on Mac or Windows, we see just one folder.

DasBlog as a single folder in VS Code

Turns out that six months ago one of us introduced another folder with the name dasblog while the original was DasBlog. When we checked them on Mac or Windows the files ended up in merged into one folder, but on Linux they were/are two, so the build fails.

You can fix this in a few ways. You can rename the file in a case-sensitive way and commit the change:

git mv --cached name.txt NAME.TXT

Please take care and back up anything you don't understand.

If you're renaming a directory, you'll do a two stage rename with a temp name.

git mv foo foo2
git mv foo2 FOO
git commit -m "changed case of dir"

Be safe out there!


Sponsor: Looking for a tool for performance profiling, unit test coverage, and continuous testing that works cross-platform on Windows, macOS, and Linux? Check out the latest JetBrains Rider!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb
Sunday, June 30, 2019 2:28:51 PM UTC
I've encountered this when renaming from within Visual Studio where changing the file name capitalization only (i.e. ClassDTO => ClassDto). It really messes things up.
Dave
Sunday, June 30, 2019 3:32:13 PM UTC
I've encountered this issue with git on more than one occasion, in my case usually because my local branch has different casing than the remote branch.

Another workaround in Windows 10 is to enable folder case sensitivity: https://www.howtogeek.com/354220/how-to-enable-case-sensitive-folders-on-windows-10/

Here be dragons though, as it can break unaware apps.
Monday, July 01, 2019 7:59:00 PM UTC
Will the rewrite of DasBlog fix the DST Bug previously mentioned?
Dave S.
Tuesday, July 02, 2019 3:28:56 PM UTC
This is the worst. I ran into this issue a couple years ago multiple times with a couple of the other engineers on our team. Three of us independently (on purpose, different features but same shared folder) created the same folder but with different casing. It highlighted that a) we needed to better on enforcing naming conventions b) we should have only one person created it on the source branch with placeholder content, merge into our dev lines, and continue from there.

Had to use the same method you suggested -- move, move -- to fix it.
Wednesday, July 03, 2019 1:45:25 AM UTC
Git could use a canonical capitalization option. With wrong casing files and folders being renamed automatically.
Wednesday, July 03, 2019 10:57:06 PM UTC
Some things are just stupid. Case sensitive file and folder names being one. Different date formats across the world being another - year/month/day is the solution case closed.
Paul
Friday, July 12, 2019 4:03:29 PM UTC
his is the worst. I ran into this issue a couple years ago multiple times with a couple of the other engineers on our team. Three of us independently (on purpose, different features but same shared folder) created the same folder but with different casing. It highlighted that a) we needed to better on enforcing naming conventions b) we should have only one person created it on the source branch with placeholder content, merge into our dev lines, and continue from there.
Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.