将git中的目录重命名为小写,同时ignoreLowercase = True的问题 [英] Issue with renaming a directory in git to lowercase while ignoreLowercase=True

查看:154
本文介绍了将git中的目录重命名为小写,同时ignoreLowercase = True的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 #在分支大师
#没有为commit提交更改:
#(使用git add< file> ...更新将提交的内容)
#(使用git checkout - - < file> ...放弃工作目录中的更改)

#modified:DIR / a

然而,在我的工作目录中,我发现这个文件实际上叫做 dir / a (注意小写字母 dir 而不是 DIR )。

问题:我想将这个已修改的 a 文件添加到暂存区并提交,但我希望它与我的工作目录(它显示 dir / a ) - ,而不是git将它视为 DIR / a


$ b

重要提示:

不幸的是,我可以因为 DIR / a 实际上并不存在于工作树中,所以不要简单 git mv DIR / a dir / a



目前我的 .git / config 文件显示 ingorecase = true ,所以我知道我必须将其设置为false。然而,除了改变这个标志之外什么都不做,现在这个 git status 揭示了:

 #在分支master上
#没有为commit提交更改:
#(使用git add< file> ...更新将提交的内容)
# (使用git checkout - < file> ...放弃工作目录中的更改)

#修改:DIR / a

#未记录文件:
#(使用git add< file> ...来包含将要提交的内容)

#dir /

因为git只跟踪内容,所以我期望这个,切换ignorecase会让git认为添加了一个新文件。不幸的是,git现在认为我有两个文件被修改,实际上我只有一个。我希望 git status 只显示 dir / a (因为它在我的工作目录中)而不是 DIR / a ,与最近刚制作的 a 差不多。



其他注意事项

如果您对首先出现如此不稳定的情况感到好奇,我已经设法复制我最初将我的目录从 DIR 重命名为 dir 时犯的愚蠢错误。如果你认为这将有助于解决这个问题,我会很乐意做一个编辑来揭示我是如何错误地让git变得困惑的。 (它涉及到我意外击中 mv 而不是 git mv ,并且不知道 ignorecase 标记并将其保留为 ignorecase = true )。

解决方案

我找到了一个解决方法。我不确定是否有更优雅的解决方案,但我已经测试过,它确实有效。
因为git会一直认为只有一个文件存在,所以我必须完全复制目录,删除git所追踪的文件,然后将复制的目录复制到原始目录中。 dir 中需要提交的文件。



(2) cp -r dir tempDir



(3) git add tempDir /



(4) git rm -r dir Dir p>

(5) git commit -m将dir临时重命名为tempDir



(6) git mv tempDir mms



(7) git commit -m从DIR完整重命名为dir complete


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

解决方案

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"

这篇关于将git中的目录重命名为小写,同时ignoreLowercase = True的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆