A case-only rename of a file (eg.
README.md) can turn out to be very annoying. If all developers working on your codebase use a case sensitive file system, stop reading and celebrate. Case-only renames are like any other rename and you’ll be fine.
At Procurios, most developers either use a Linux distribution or a Mac (OS X). By default, OS X operates using a case insensitive file system. A seemingly simple rename of
Timeline.php might give you more issues than you’d expect.
The underlying issue of performing a rename on a case insensitive file system is that the Git status remains the same after the rename. Most of the Git commands won’t work with the new name, because the index still contains the old name.
We’ve had situations where files were duplicated, even though on OS X this wasn’t visible. On Linux you’d see the duplicate files, and notice that the changes are spread across the original and renamed files. This can be very tough to fix if you’re late at catching what was going on.
Turns out that there’s an easy fix. Use
git mv --force TimeLine.php Timeline.php to perform a case-only rename. The force flag renames a file even if the target exists. No matter what file system you use, this will force Git to record the rename as a change and record it to the index.
You might have heard of Git’s
ignorecase flag that seems to get Git to recognize case-only changes. Don’t use it. It’s a workaround that fails. For example, after renaming
File.js, I executed
git status just to see that Git recorded that
File.js has been added, without removing
file.js. Unreliable to say the least.
Another option is to create a case sensitive file system on your Mac (using Disk Utility). Use that file system for your codebase and you’ll be fine. Some developers suggest to use a microSD card (formatted as case sensitive, journaled) to store their Git projects. I might give that a try whenever (release them already!) those new MacBooks arrive :)