Git is case-sensitive and your filesystem may not be - Weird folder merging on Windows
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.
But when we clone it on Mac or Windows, we see just one folder.
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.
About Newsletter
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.
Had to use the same method you suggested -- move, move -- to fix it.
Comments are closed.