Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

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).

question from:https://stackoverflow.com/questions/13201906/issue-with-renaming-a-directory-in-git-to-lowercase-while-ignorelowercase-true

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...