将 git 中的目录重命名为小写而 ignoreLowercase=True 的问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13201906/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:42:09  来源:igfitidea点击:

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

git

提问by smaccoun

When I type git status, I see:

当我输入时git status,我看到:

# 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 dirinstead of DIR).

但是,在我的工作目录中,我看到实际上调用了该文件dir/a(注意小写dir而不是DIR)。

Question:I want to add this modified afile 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?

问题:我想将此修改后的a文件添加到暂存区并提交,但我希望它在我的工作目录(显示dir/a)中保持原样DIR/a-而不是 git 将其视为. 我怎样才能做到这一点?

Important Note:

重要的提示:

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

不幸的是,我不能仅仅git mv DIR/a dir/a因为DIR/a它实际上不存在于工作树中。

Currently my .git/configfile 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 statusof this now reveals:

目前我的.git/config文件显示为ingorecase = true,所以我知道我必须将其设置为 false。但是,除了更改此标志之外什么都不做之后,其中的一个git status现在显示:

# 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 statusto simply show dir/a(as it is in my working directory) instead of DIR/a, with the same diffs of aI had just recently made.

我预料到了这一点,因为 git 只跟踪内容,而切换 ignorecase 会使 git 认为添加了一个新文件。不幸的是,git 现在认为我有两个被修改的文件,而实际上我只有一个。我想git status简单地显示dir/a(因为它在我的工作目录中)而不是DIR/a, 与a我最近所做的相同。

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 DIRto 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 mvinstead of git mv, and being unaware of the ignorecaseflag and leaving it as ignorecase=true).

如果你是好奇,这样一个不稳定的局势摆在首位如何产生的,我已成功地复制时,最初是从我改名目录的情况下,我做出了愚蠢的错误DIRdir。如果您认为这有助于解决此问题,我很乐意进行编辑,以揭示我是如何错误地使 git 如此困惑的。(这涉及我不小心击中mv而不是git mv,并且不知道该ignorecase标志并将其保留为ignorecase=true)。

回答by Eduardo Duran Diaz

Example: if you are lower-casing Mydir

示例:如果您使用的是小写 Mydir

git mv src/Mydir src/mydirs

git mv src/mydirs src/mydir

git commit -m "Rename folder Mydir to mydir"

回答by smaccoun

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.

我找到了解决方法。我不确定是否有更优雅的解决方案,但我已经测试过它并且它确实有效。因为当只有一个文件时 git 继续认为存在两个文件,我实际上只需要完全复制目录,删除 git 作为文件跟踪的内容,然后将复制的目录 mv 恢复到原始目录。

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

(1) 提交任何dir需要提交的文件。

(2) cp -r dir tempDir

(2) cp -r dir tempDir

(3) git add tempDir/

(3) git add tempDir/

(4) git rm -r dir Dir

(4) git rm -r dir Dir

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

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

(6) git mv tempDir mms

(6) git mv tempDir mms

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

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