Tim Randall
Tim Randall

Reputation: 4145

How to change the case of a filename

Some time ago, someone pushed a file to the github repository whose name is the wrong case. Now there is a new version of the file, which has the correct case in its filename.

When I push the new version to github and create a pull request, the "Files Changed" view shows a new file and no changes to the old file. In other words, if I merge this pull request, the file's history will break.

When I was working with git in a bash shell, this didn't usually happen. As long as the file was similar enough, the change was interpreted as a "rename" and its history was preserved. Is there a way to do this in github?

Upvotes: 0

Views: 1325

Answers (1)

bk2204
bk2204

Reputation: 76499

The case you're describing is not what Git typically considers a rename. Generally, a rename in Git is when one file is removed in the same commit as another file is added and the files are identical or similar.

In your case, the old file hasn't been removed, so you now have two files. If they are identical or similar, Git will consider this a copy, but not a rename. Git uses a similar technique to detect them, but they aren't the same.

The way to handle this depends on the operating system you're on. If you're on a system that's case sensitive, like Linux, FreeBSD, or a case-sensitive macOS, then you can just delete the old file with git rm as part of your commit. If you're on a case-insensitive system, then you should use git mv -f to rename the old file to the new one.

All of this assumes that your commit (and pull request) introduce the new file. If both files already exist in the repository history, then there's no way to make Git detect them as renames now.

Upvotes: 3

Related Questions