Git 区分大小写

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8904327/
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-10 12:46:11  来源:igfitidea点击:

Case sensitivity in Git

gitcase-sensitive

提问by entropid

I've run into a problem with git. Basically I set to false core.ignorecasebecause I wanted to change the case of the names of some folders (since I'm under OSX with a case-insensitive filesystem, the changes weren't shown otherwise). When I pulled my data, I've noticed that now every renamed folder appears twice on the repository, with both the old and the new name. I don't know what to do to remove the old folders since they don't appear locally (I've try to set core.ignorecaseto true again but it isn't helping).

我遇到了 git 问题。基本上,我设置为 falsecore.ignorecase是因为我想更改某些文件夹名称的大小写(因为我在 OSX 下使用不区分大小写的文件系统,因此不会以其他方式显示更改)。当我提取我的数据时,我注意到现在每个重命名的文件夹在存储库中出现两次,旧名称和新名称。我不知道如何删除旧文件夹,因为它们没有出现在本地(我已经尝试core.ignorecase再次设置为 true 但它没有帮助)。

回答by VonC

May be a workaround similar to this comment in an msysgit issue(for another case-insensitive OS: Windows) could help?

可能是类似于msysgit 问题中的此评论的解决方法(对于另一个不区分大小写的操作系统:Windows)有帮助吗?

I've encountered this same issue. Refactored a package name in Eclipse and switching to a previous build broke due to the folder name not reverting. I'm using Windows 7, Git 1.7.0.2.msysgit.0

My folder was renamed in Windows to "folder" but was displayed as "Folder" in Git.
I fixed the issue by renaming it to "Folder" in Windows and then running:

我遇到过同样的问题。在 Eclipse 中重构了一个包名并切换到以前的构建由于文件夹名称没有恢复而中断。我使用的是 Windows 7,Git 1.7.0.2.msysgit.0

我的文件夹在 Windows 中被重命名为“ folder”,但Folder在 Git 中显示为“ ”。
我通过Folder在 Windows 中将其重命名为“ ”然后运行来解决该问题:

git mv "Folder" "Folder2"
git mv "Folder2" "folder"


Note that since git 2.0.1 (June 2014), git mv Folder foldershould just work!

请注意,自 git 2.0.1(2014 年 6 月)以来,git mv Folder folder应该可以正常工作!

See "Git: Changing capitalization of filenames"

请参阅“ Git:更改文件名的大小写

回答by adib

You can create a disk image (preferably a sparsebundle disk image) with a case-sensitive file system and checkout your git repository there.

您可以使用区分大小写的文件系统创建磁盘映像(最好是 sparsebundle 磁盘映像)并在那里检出您的 git 存储库。

The Disk Utility screenshot below shows how to create a case-sensitive disk image.

下面的磁盘工具屏幕截图显示了如何创建区分大小写的磁盘映像。

Disk Utility Settings

磁盘工具设置

回答by Brandon Yang

Use the following command on macOS. This will change your git configuration to be case sensitive on filenames.

在 macOS 上使用以下命令。这会将您的 git 配置更改为对文件名区分大小写。

git config core.ignorecase false

You can set this globally by editing ~/.gitconfigand setting it under coresuch as:

您可以通过编辑~/.gitconfig和设置来全局设置它,core例如:

[core]
    ignoreCase = false

回答by Arafangion

Mac OS X by default is "case insensitive but case preserving". This is an important distinction.

Mac OS X 默认是“不区分大小写但保留大小写”。这是一个重要的区别。

I suggest you create another disk image, and specifically format it as "HFS Case Sensitive".

我建议您创建另一个磁盘映像,并专门将其格式化为“HFS Case Sensitive”。

回答by Mohamed EL HABIB

git mv "Folder" "Folder2"
git mv "Folder2" "folder"
git commit -a -m "my message"

回答by Philip Oakley

There is a longish recent thread on case sensitivity issues on the [email protected] discussion forum titled Bug? Git checkout fails with a wrong error messagewhich highlights the issues, and things to try, of case sensitivity between different platforms.

最近在 [email protected] 讨论论坛上有一个关于区分大小写问题的长帖子,标题为Bug?Git checkout 失败并显示错误的错误消息,该消息突出显示了不同平台之间区分大小写的问题和要尝试的事情。