windows 如何让 git 忽略更改以防万一?

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

How to make git ignore changes in case?

windowsgit

提问by 1800 INFORMATION

I'm not too sure what is going on here, but sometimes a particular file in my repository will change the case of it's name. e.g.,:

我不太确定这里发生了什么,但有时我的存储库中的特定文件会更改其名称的大小写。例如,:

before: File.h

前: File.h

after: file.h

后: file.h

I don't really care why this is happening, but this causes git to think it is a new file, and then I have to go and change the file name back. Can you just make git ignore case changes?

我真的不在乎为什么会发生这种情况,但这会导致 git 认为它是一个新文件,然后我必须将文件名改回来。你可以让 git 忽略大小写更改吗?

[edit]I suspect it is Visual Studio doing something weird with that particular file, because it seems to happen most often when I open and save it after changes. I don't have any way to fix bugs in VS however, but git should be a bit more capable I hope.

[编辑]我怀疑是 Visual Studio 对那个特定文件做了一些奇怪的事情,因为当我打开并在更改后保存它时,它似乎最常发生。然而,我没有任何方法可以修复 VS 中的错误,但我希望 git 应该更有能力。

回答by MarkB

Since version 1.5.6 there is an ignorecaseoption available in the [core]section of .git/config

由于1.5.6版本有一个ignorecase在可用选项[core]的部分.git/config

e.g. add ignorecase = true

例如添加 ignorecase = true

To change it for just one repo, from that folder run:

要仅为一个 repo 更改它,请从该文件夹运行:

git config core.ignorecase true

To change it globally:

要全局更改它:

git config --global core.ignorecase true

回答by Andrew Arnott

You can force git to rename the file in a case-only way with this command:

您可以使用以下命令强制 git 以仅区分大小写的方式重命名文件:

git mv --cached name.txt NAME.TXT

Note this doesn't change the case of the file in your checked out copy on a Windows partition, but git records the casing change and you can commit that change. Future checkouts will use the new casing.

请注意,这不会更改 Windows 分区上已检出副本中文件的大小写,但 git 会记录大小写更改,您可以提交该更改。未来的结账将使用新的外壳。

回答by John C

In git version 1.6.1.9 for windows I found that "ignorecase=true' in config was already set by default.

在适用于 Windows 的 git 版本 1.6.1.9 中,我发现默认情况下已经设置了配置中的“ignorecase=true”。

回答by akauppi

The situation described in the question is now re-occuring with Mac OS X, git version >= 1.7.4 (I think). The cure is to set your ignorecase=false and rename the lowercased files (that git changed that way, not Visual Studio) back to their UsualCase by hand (i.e. 'mv myname MyName').

问题中描述的情况现在在 Mac OS X 中重新出现,git 版本 >= 1.7.4(我认为)。解决方法是设置您的ignorecase=false 并手动将小写文件(git 以这种方式更改,而不是Visual Studio)重命名回它们的UsualCase(即'mv myname MyName')。

More info here.

更多信息在这里