package
Detect file name case changes in a Git repository
npm install git-detect-case-changeGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Detect and fix case-only filename changes that Git can't see on macOS/Windows.
On case-insensitive filesystems, renaming utils.ts → Utils.ts won't register in Git. This tool detects those mismatches and fixes them.
# Renamed foo.js → Foo.js but Git didn't notice?
npx git-detect-case-change # Stage the case rename in Git
npx git-detect-case-change --fix-local # Rename local files to match GitSupport this project by ⭐️ starring and sharing it. Follow me to see what other projects I'm working on.
The tool works in two directions depending on which casing is correct:
| Scenario | Command | Effect |
|---|---|---|
| Local is the source of truth | npx git-detect-case-change | Stages the rename with git mv |
| Git is the source of truth | npx git-detect-case-change --fix-local | Renames local files to Git's case |
Example output:
$ npx git-detect-case-change
src/utils.ts -> src/Utils.ts
lib/helper.js -> lib/Helper.jsPreview changes without modifying anything:
npx git-detect-case-change --dry
npx git-detect-case-change --fix-local --dryExits with code 1 if mismatches are found, useful as a lint step or pre-commit hook:
npx git-detect-case-change --checknpx git-detect-case-change -- <dir-or-file>npx git-detect-case-change --since HEAD~3
npx git-detect-case-change --fix-local --since ORIG_HEADAutomatically fix case mismatches after every git pull or git merge:
.git/hooks/post-merge:
#!/bin/sh
# post-merge — fix case mismatches introduced by the merge
set -e
# ORIG_HEAD points to where HEAD was before the merge
git rev-parse --verify ORIG_HEAD >/dev/null 2>&1 || exit 0
# Only check files that changed in the merge (fast even in large repos)
./node_modules/.bin/git-detect-case-change --fix-local --since ORIG_HEADMake the hook executable: chmod +x .git/hooks/post-merge
macOS and Windows default to case-insensitive filesystems. Git respects the underlying filesystem, so it can't reliably detect case-only renames.
The official workaround is:
git mv <old-path> <new-path>This gets tedious when:
This tool automates that detection. See this StackOverflow discussion for more context.
Reads file paths from Git's index:
git ls-tree --name-only -z -r HEAD-z uses NUL terminators so filenames with spaces or special characters are safe.
Detects case mismatches:
Walks each Git path segment-by-segment, looking up directory entries with fs.readdir.
Reads are memoized by resolved path so each unique parent directory is read at most once, regardless of how many files it contains.
Lookups are case-insensitive and Unicode-normalized (NFC) to correctly match files stored in NFD form on macOS/Windows filesystems.
Applies fixes based on mode:
Default mode: Stages changes with git mv <git-path> <local-path>
--fix-local mode: Renames local files/directories to match Git's case:
file.tmp-<pid>-<timestamp>) to work around case-insensitive filesystem limitationsEstimated unpacked size across 1 packages.
57.2 kB
Includes dependencies.