【问题标题】:Cannot add to repository无法添加到存储库
【发布时间】:2021-08-20 06:07:04
【问题描述】:

当我使用 git add 时出现错误。

 $ git add .
    error: short read while indexing .editorconfig
    error: .editorconfig: failed to insert into database
    error: unable to index file '.editorconfig'
    fatal: adding files failed

我该如何解决?

【问题讨论】:

  • 您是否有另一个文件名称相同但大小写不同,例如.Editorconfigyoutrack.jetbrains.com/issue/IDEA-257266
  • @WillWalsh 我的 .ediconfig
  • root = true [] charset = utf-8 end_of_line = lf insert_final_newline = true indent_style = space indent_size = 4 trim_trailing_whitespace = true [.md] trim_trailing_whitespace = false [*. {yml,yaml}] indent_size = 2
  • 你在使用 Git for Windows 吗?正如我发送的 URL 中所述,这可能是由于 Git 尝试添加不同大小写的相同文件名。
  • 是的,我正在使用 git for windows

标签: git github gitlab


【解决方案1】:

这 (error: short read while indexing <em>name</em>) 发生在 Git 找到给定名称的文件,从操作系统 about 获取该文件的信息并将该文件添加到索引(即暂存区)时。吉特:

  • 使用文件名打开文件;
  • 读取文件内容;和
  • 发现虽然系统说文件的长度正好是 N1 个字节,但 Git 只能读取 N0 个字节,其中 N0 N1.

在 Git-for-Windows 上使用 WSL 时,有一个新功能,您可以允许系统存储两个文件,它们仅在某些名称的 case 上有所不同,例如 readme.txt README.TXT。通常 Windows 只允许 one 这样的名称,并且一旦名称存在,使用任何变体(包括 ReAdMe.TxTreaDME.tXT 或其他任何名称)都会为您提供一个文件。 Git-for-Windows 过多地利用了这一假设,而 WSL 现在已经打破了这一假设。

目前的解决方案是:

  • 不要这样做,和/或
  • 不要使用 Windows。1

最终,Git-for-Windows 人员将构建一个 Git-for-Windows 版本来解决该问题。


1这里的 macOS 人可能会嘲笑 Windows 人,但 macOS 也有类似的问题。在某些方面,macOS 问题可能更糟(NFC 与 NFD 名称),但在其他方面,Windows 问题更糟(无法创建名为 aux.caux.h 的文件)。 Git 在这里确实需要一个适当的通用机制,但在某些方面这是一个无法解决的问题。

【讨论】:

  • 我在使用 Kubuntu 遇到这个问题?
  • @no_one:我没用过Kubuntu,但是基于Ubuntu,一般不应该有这些问题。不过,他们可能已经添加了 Windows 文件系统并添加了这个有问题的 Windows 功能。
猜你喜欢
  • 2012-09-23
  • 2011-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-17
  • 2020-10-18
相关资源
最近更新 更多