The problem with renaming the directory in git to lowercase and 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 file a to the staging area and commit, but I want it to be the same as in my working directory (which shows dir/a ) - unlike the way git sees it as dir/a . How can i do this?

Important Note:

Unfortunately, I cannot just git mv DIR/a dir/a , because dir/a does not actually exist in the working tree.

Currently, my .git/config file shows ingorecase = true , so I know that I need to set the value to false. However, after he changed this flag, now git status shows:

 # 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 will make git think about adding a new file. Unfortunately, git now thinks that I have two files that change when in fact I only have one. I want git status simply display dir/a (as in my working directory) instead of dir/a with the same a differences that I recently did.

Additional note

If you are interested in how such an unstable situation arose, I was able to reproduce the stupid mistakes that I made when they initially renamed the case of my directory from dir to dir . If you think that this will help in solving this problem, I would be happy to make an edit that will show how I mistakenly made git so confusing. (this leads to a random hit of mv instead of git mv and ignorance of the ignorecase flag and leaving it as ignorecase=true ).

+8
git
source share
2 answers

I found a workaround. I'm not sure if there is a more elegant solution, but I checked this and it works. As git continues to think that two files exist when only one does, I had to actually copy the directory completely, delete what git is being tracked as a file, and then the mv copied directory goes back to the original.

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

(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"

+16
source share

Example: if you use the Mydir lower case

 git mv src/Mydir src/mydirs git mv src/mydirs src/mydir git commit -m "Rename folder Mydir to mydir" 
+19
source share

All Articles