Scott Hanselman

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

June 28, 2019 Comment on this post [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
Hosting By
Hosted in an Azure App Service
June 30, 2019 18:28
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.
June 30, 2019 19:32
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.
July 01, 2019 23:59
Will the rewrite of DasBlog fix the DST Bug previously mentioned?
July 02, 2019 19:28
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.
July 03, 2019 5:45
Git could use a canonical capitalization option. With wrong casing files and folders being renamed automatically.
July 04, 2019 2:57
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.
July 12, 2019 20:03
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.