gpt4 book ai didi

git - 将 git config core.ignorecase 设置为 false 是个好主意吗?

转载 作者:行者123 更新时间:2023-12-04 13:17:55 25 4
gpt4 key购买 nike

我的团队目前管理跨多个文件系统的 git 存储库。我们大多数人使用 Windows,但我们中的一些人使用 Linux。另外,我们将生产代码部署在 Linux 服务器上。这导致了我们代码库中文件名大小写的多个问题(即,当文件实际上是 Foo.js 时导入 foo.js )。最近,我完成了对项目文件夹的清理工作,主要包括重新组织目录并将目录/文件重命名为通用命名标准。许多文件名更改正在改变文件的大小写(例如 foo.js -> Foo.js )。

当我进行这些更改时,我并不完全了解 git 如何在区分大小写和不区分大小写的文件系统上以不同的方式处理文件名,这导致了很多奇怪的错误。我在研究这个时遇到的一件事是 ignorecase 中的 .gitconfig 值。

从 git-config 文档:

Internal variable which enables various workarounds to enable Git to work better on filesystems that are not case sensitive, like APFS, HFS+, FAT, NTFS, etc. 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".

Git relies on the proper configuration of this variable for your operating and file system. Modifying this value may result in unexpected behavior.



根据我从中可以理解的内容,设置 ignorecase = true 将使得如果 git 检测到相同的文件名但大小写不同,它将更改 git 索引中的名称以匹配文件系统上的内容(即,如果 Windows有 foo.js 和 git checkout/pull 有 Foo.js ,它会假设 foo.js 是正确的,git 将使用那个大小写)。我担心的是如果我推送到远程并且我们的部署服务器接受更改会发生什么。然后它会尝试导入不存在的 Foo.js 并出错。

但是,通过设置 ignorecase = false ,git 应该能够检测到文件名存在差异并正确替换文件。这是正确的,我是否应该让我的团队将此值设置为 false,因为我们跨不同的文件系统工作?

我读过人们说你绝对应该这样做的帖子,以及一些完全相反的帖子。

最佳答案

From what I'm able to understand from this, setting ignorecase = true will make it so that if git detects the same file name but with different casing, it will change the name in the git index to match what is on the filesystem (i.e. if Windows has foo.js and a git checkout/pull has Foo.js, it will assume that foo.js is correct and git will use that casing).



不,这是倒退:文档指出,如果索引当前包含 Foo.js ,无论出于何种原因,工作树都有 foo.js , Git 会假设 foo.js真的是 Foo.js并将把 Foo.js进入下一次提交。与 core.ignorecase设置为 false ,然而,Git 完全相信工作树: git add .将删除大写名称(和内容)并使用小写名称 foo.js根据工作树中的副本在索引中安装新副本。

(要查看索引中的内容,请使用 git ls-files --stage ,或省略 --stage 以仅获取文件名。请注意,这会转储整个索引内容!添加路径参数以选择特定文件,例如, git ls-files "[Ff]oo.js" ,只查找那些文件。在类 Unix 的 shell 中需要引号,例如 bash,以防止 shell 在此处解释元字符 [Ff]。shell 将删除引号。在其他 Windows 特定命令中使用什么行口译员,我不确定。)

一般来说,您不应该更改 core.ignorecase .如果要重命名文件,最直接的方法是使用 git mv (同时调整索引和工作树)。如果您只想更改大小写,您可以 git mv两次:
git mv foo.js temporary-name
git mv temporary-name Foo.js

现在你有 Foo.js在索引和工作树中都有一个初始资本。某些版本的 Git 或许可以在没有中间临时名称的情况下处理这个问题,但是当您使用中间名称时,所有版本都会做正确的事情。

关于git - 将 git config core.ignorecase 设置为 false 是个好主意吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58192285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com