git 不区分大小写吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8481488/
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
Is git not case sensitive?
提问by JAkk
In the first commitment of my partial called _Electronics
it was written beginning with a capital letters, then I changed it to _electronics
.
在我的部分调用的第一个承诺中,_Electronics
它以大写字母开头,然后我将其更改为_electronics
.
Git under cygwin ignored the case after commiting the new name, so I changed the name by hand in the target repo.
cygwin下的Git在提交新名称后忽略了大小写,所以我在目标repo中手动更改了名称。
Now it sometimes changes the commited _electronics
partial to _Electronics
.
现在它有时会将_electronics
提交的部分更改为_Electronics
.
What have I done wrong?
我做错了什么?
采纳答案by Adam Dymitruk
It will be seen as 2 different things but will cause you issues on a non-case-sensitive system. If this is the case, ensure you are tab-completing any paths or file names. Further, to change the name of something in just the case, do this:
它将被视为 2 种不同的东西,但会导致您在不区分大小写的系统上出现问题。如果是这种情况,请确保您使用制表符完成任何路径或文件名。此外,要在这种情况下更改某些内容的名称,请执行以下操作:
mv file.txt temp.txt
git add -A
git commit -m "renaming..."
mv temp.txt File.txt
git add -A
git commit --amend -m "Renamed file.txt to File.txt"
This is an explicit way of making changes committing them, then collapsing the commits. A shorter way to do it is to manipulate the index and working folder all in one:
这是一种明确的方式来进行更改提交,然后折叠提交。一种更短的方法是将索引和工作文件夹合二为一:
git mv file.txt temp.txt
git mv temp.txt File.txt
git commit -m "Renamed file.txt to File.txt"
This is related to adjusting directory names as well: git mv and only change case of directory
这也与调整目录名称有关:git mv 并且仅更改目录的大小写
回答by manojlds
It is going to depend on the core.ignorecase
configuration value, which is set to false in case-sensitive filesystems and true in msysgit on Windows.
这将取决于core.ignorecase
配置值,该值在区分大小写的文件系统中设置为 false,在 Windows 上的 msysgit 中设置为 true。
core.ignorecase
If true, this option enables various workarounds to enable git to work better on filesystems that are not case sensitive, like FAT. For example, if a directory listing finds "makefile" when git expects "Makefile", git will assume it is really the same file, and continue to remember it as "Makefile".
The default is false, except git-clone(1) or git-init(1) will probe and set core.ignorecase true if appropriate when the repository is created.
core.ignorecase
如果为 true,则此选项启用各种变通方法,以使 git 在不区分大小写的文件系统(如 FAT)上更好地工作。例如,如果目录列表在 git 期望“Makefile”时找到“makefile”,则 git 将假定它确实是同一个文件,并继续将其记住为“Makefile”。
默认为 false,除了 git-clone(1) 或 git-init(1) 将在创建存储库时探测并设置 core.ignorecase 为 true。
More detail in this reply to Changing capitalization of filenames in Git.
在这个对在 Git 中更改文件名大小写的回复中的更多详细信息。
回答by Arnoud
This is far easier:
这要容易得多:
git mv Electronics electronics -f
git commit -m "That was easy!"
回答by Cemo
git config --system core.ignorecase false
回答by Jeroen Vannevel
In my scenario I had two folders tests
and Tests
which showed as two separate folders in Github but a single Tests
folder in Windows. My aim was to combine them both into tests
.
在我的场景中,我有两个文件夹tests
,Tests
它们在 Github 中显示为两个单独的文件夹,但Tests
在 Windows 中显示为一个文件夹。我的目标是将它们结合到tests
.
I used the following approach:
我使用了以下方法:
- Create a new folder
temp
- Copy all content from
Tests
totemp
- Delete
Tests
- execute
git rm Tests -r
- Rename
temp
totests
- 新建一个文件夹
temp
- 将所有内容复制
Tests
到temp
- 删除
Tests
- 执行
git rm Tests -r
- 重命名
temp
为tests
回答by Nitesh Goyal
I have tried to solve the issue and it was successful on Windows10
我已尝试解决该问题并在 Windows10 上成功
Lets suppose there are two folders on bitbucket TEST and test but when I clone repo on disk it creates only TEST and I want to keep test as single folder on git which contains all files.
假设 bitbucket TEST 和 test 上有两个文件夹,但是当我在磁盘上克隆 repo 时,它只创建了 TEST,我想将 test 保留为包含所有文件的 git 上的单个文件夹。
I will need to execute following commands on command line git mv TEST test1 -f git mv text1 test -f git commit -m "renaming..." git push
我需要在命令行 git mv TEST test1 -f git mv text1 test -f git commit -m "renaming..." git push 上执行以下命令
Now you will see that folder hierarchy is corrected on bitbucket.
现在您将看到在 bitbucket 上更正了文件夹层次结构。