gpt4 book ai didi

git - 如何在文件名大小写更改时切换分支?

转载 作者:太空狗 更新时间:2023-10-29 13:42:19 24 4
gpt4 key购买 nike

  1. 我有一个分支 development,其中有一个文件 Config.json
  2. 我正在创建一个新分支 new_development,我将 Config.json 重命名为 config.json 并提交。
  3. 我切换回 development 以查看该分支中的某些内容是如何制作的。没有错误。
  4. 我切换到 new_development 以继续研究新事物。它显示错误:

error: The following untracked working tree files would be overwritten by checkout:

   Config.json

Please move or remove them before you switch branches.

Aborting

该文件实际上是在 git 中。

我有这个 git 配置:

[core]
ignorecase = false

当相同的文件有不同的大小写时,如何进行分支切换?

最佳答案

How do I make branches switching work when the same files have different case?

core.ignoreCase 改回 true

你在一个大小写不敏感文件系统上; git 使用 core.ignoreCase 设置来表明这一点。它在您创建存储库时配置(通过 git init 或通过 git clone):git 查看您的文件系统以确定它是否区分大小写,并将其缓存信息(在 core.ignoreCase 设置中),这样它就不必为每个操作都执行此查找。

这不是您可以更改的设置。

core.ignoreCase = false,在大小写不敏感文件系统上:

% git ls-tree HEAD
100644 blob 257cc5642cb1a054f08cc83f2d943e56fd3ebe99 foo
% git ls-tree branch
100644 blob bcc9cdfd113753edf279e92afd622b0f3bb05fbc FOO
% git checkout branch
error: The following untracked working tree files would be overwritten by checkout:
FOO
Please move or remove them before you switch branches.
Aborting

这是因为我已经告诉 git 我的文件系统 区分大小写。它查看我正在尝试检查的树,发现在我当前的 HEAD 树中有一个名为 FOO 的文件 not , 然后在磁盘上查看是否有同名的未跟踪工作文件。它stats 文件FOO(这实际上是文件foo,因为我们在一个不区分大小写的文件系统上)并且意识到你有一个工作目录中未跟踪的文件。

当然,除了你没有。您有文件 foo

如果我更正这个问题,设置 core.ignoreCase 来反射(reflect)我的文件系统的实际情况,那么我就可以正确地切换分支:

% git config core.ignoreCase true
% git checkout branch
Switched to branch 'branch'
% git ls-tree HEAD
100644 blob bcc9cdfd113753edf279e92afd622b0f3bb05fbc FOO

关于git - 如何在文件名大小写更改时切换分支?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50096060/

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