https://github.com/privatenumber/git-detect-case-change
🤖 Script to detect file name case changes in a Git repository
https://github.com/privatenumber/git-detect-case-change
case case-sensitive detection git rename
Last synced: about 1 year ago
JSON representation
🤖 Script to detect file name case changes in a Git repository
- Host: GitHub
- URL: https://github.com/privatenumber/git-detect-case-change
- Owner: privatenumber
- License: mit
- Created: 2021-11-20T07:55:46.000Z (over 4 years ago)
- Default Branch: develop
- Last Pushed: 2023-01-28T06:04:48.000Z (over 3 years ago)
- Last Synced: 2025-03-17T18:53:50.643Z (over 1 year ago)
- Topics: case, case-sensitive, detection, git, rename
- Language: TypeScript
- Homepage:
- Size: 351 KB
- Stars: 29
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# git-detect-case-change
Script to stage file-path case changes in a Git repository.
Support this project by ⭐️ starring and sharing it. [Follow me](https://github.com/privatenumber) to see what other cool projects I'm working on! ❤️
## Usage
After renaming files, run the script with [npx](https://nodejs.dev/learn/the-npx-nodejs-package-runner) in your Git repository:
```sh
npx git-detect-case-change
```
If there were any case-changes, it will detect and stage them for you.
#### Dry run
Run with `--dry` to see what files would be renamed before staging them:
```sh
npx git-detect-case-change --dry
```
#### Scoping files
Pass in specific paths after `--` to scope the search to:
```sh
npx git-detect-case-change --
```
## Why?
File-systems on macOS & Windows are _case-insensitive_ by default, which means paths `/a.txt` and `/A.txt` cannot exist at the same time. Because of this default, Git is also case-insensitive by default, preventing it from detecting case changes in file names.
The recommended solution
from this [StackOverflow discussion](https://stackoverflow.com/questions/17683458/how-do-i-commit-case-sensitive-only-filename-changes-in-git) is to rename the files individually with `git mv`:
```sh
git mv
```
However, this may not be practical if the case-changes were made without Git (eg. automated by another program) and there's a lot to rename.
This script automates case-change detection for Git.
## How does it work?
1. Get the case-sensitive file paths from the current Git project:
```sh
git ls-tree --name-only -r HEAD
```
2. Check each file path with [`fs.promises.exists`](https://github.com/privatenumber/fs.promises.exists) to find a case-insensitive match.
3. If the path exists with a different case, register the change with Git:
```sh
git mv
```