How to rename a file when only the upper or lower case changes (Windows, macOS and Git)
You renamed <code>Header.js</code> to <code>header.js</code>. Your computer shows the new name, Git says nothing changed, and the build server on Linux reports that the module cannot be found.
Why it is awkward
| System | Are Photo.jpg and photo.jpg different? |
|---|---|
| Windows (NTFS) | No. Names keep the case you type but compare without it. |
| macOS (APFS, default) | No, unless the disk was formatted as case-sensitive. |
| Linux (ext4 and most others) | Yes. They are two separate files and can sit side by side. |
So a change that is invisible to the rules on your laptop is a real rename on the server, in a container, or in CI.
The safe two-step rename
Move the file to a temporary name, then to the final name. Each step is a normal rename that no system can confuse.
mv -- Header.js header.tmp && mv -n -- header.tmp header.js
Rename-Item -LiteralPath 'Header.js' -NewName 'header.tmp' Rename-Item -LiteralPath 'header.tmp' -NewName 'header.js'
Older Windows PowerShell versions answer a direct case-only rename with "Source and destination path must be different". The two steps avoid that.
In a Git repository
- Rename with Git, not the file manager:
git mv Header.js header.js. If your Git version refuses, go through a temporary name:git mv Header.js tmp.jsthengit mv tmp.js header.js. - Check that it was recorded:
git statusshould showrenamed: Header.js -> header.js. - Update every import or link to the new case, then commit.
Do not switch core.ignorecase to false on a case-insensitive disk to make Git notice: Git then believes both names exist and can show phantom deletions. If a case-only rename was already committed wrongly, git ls-files | grep -i header shows which name the repository actually holds.
Renaming many files to lowercase
Load the names into the batch rename tool, choose lowercase, and it marks case-only rows and generates two-step commands for them. It also blocks the case where two files would end up as the same lowercase name, for example README.md and Readme.md.
Related
How to batch rename files safely (without uploading them) · Why a batch rename overwrites or skips files (name collisions) · Why file10 sorts before file2, and how to add leading zeros · Windows names you cannot use: CON, NUL, AUX, COM1 · Remove spaces and special characters from file names · Batch rename tool (names only, in your browser) · Compress many photos at once · Invisible characters in text
Questions
Why won't Windows let me change only the case of a file name?
Windows compares names without case, so Photo.jpg and photo.jpg are the same file. Some tools then treat the rename as a no-op or an error. Rename to a temporary name first, then to the final name.
Why does Git not see that I changed a file name's case?
On Windows and macOS Git usually runs with core.ignorecase true, so a case-only rename made outside Git can be ignored. Use git mv, or go through a temporary name with two git mv commands.
Why does my build fail on Linux after renaming a file's case?
Linux file names are case-sensitive. If an import still uses the old case, or Git still holds the old name, the file cannot be found there even though it works on your laptop.
Should I set core.ignorecase to false?
Not on a case-insensitive disk. Git would think both spellings exist and can report confusing deletions. Use git mv instead.
Can two files differ only by case?
On Linux, yes. On Windows and default macOS, no, so cloning such a repository there leaves only one of them, which is why the batch rename tool blocks that clash.
Published .