Issue with renaming a directory in git to lowercase while ignoreLowercase=True

When I type git status, I see:

# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   DIR/a
#

However, in my working directory I see that this file is actually called dir/a (note the lowercase dir instead of DIR).

Question: I want to add this modified a file to the staging area and commit, but I want it to be as it is in my working directory (which shows dir/a) - as opposed to the way git is seeing it as DIR/a. How can I do this?

Important Note:

Unfortunately, I can't simply git mv DIR/a dir/a because DIR/a doesn't actually exist in the working tree.

Currently my .git/config file shows ingorecase = true, so I know that I have to set that equal to false. However, after doing nothing but changing this flag, a git status of this now reveals:

# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   DIR/a
#
 # Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   dir/

I expected this since git only tracks content, and switching ignorecase would make git think a new file was added. Unfortunately, git now thinks that I have two files that are modified, when in fact I only have one. I want git status to simply show dir/a (as it is in my working directory) instead of DIR/a, with the same diffs of a I had just recently made.

Additional Note

If you are curious as to how such a precarious situation arose in the first place, I have managed to replicate the silly mistakes I had made when originally renaming the case of my directory from DIR to dir. If you think this would help in getting to a solution for this problem, I would be happy to make an edit that would reveal how I mistakenly made git so confused. (it involves me accidentally hitting mv instead of git mv, and being unaware of the ignorecase flag and leaving it as ignorecase=true).

Answers


Example: if you are lower-casing Mydir

git mv src/Mydir src/mydirs

git mv src/mydirs src/mydir

git commit -m "Rename folder Mydir to mydir"

I've found a workaround. I'm not sure if there's a more elegant solution, but I have tested this and it does work. Because git continues to think that two files exist when only one does, I had to actually just copy the directory entirely, remove what git is tracking as a file, and then mv the copied directory back to the original.

(1) commit any files in dir that need to be commited.

(2) cp -r dir tempDir

(3) git add tempDir/

(4) git rm -r dir Dir

(5) git commit -m "Temporary rename of dir to tempDir"

(6) git mv tempDir mms

(7) git commit -m "Full rename from DIR to dir complete"


Need Your Help