无法添加名称包含波浪号、“~”后跟数字的文件

Unable to add files with name containing tilde, '~' followed by a number

该文件夹由文件名类似 abc~1123~1a1d2~3.

的文件组成

当我做 git add --all 它说,

$ git add --all
error: Invalid path 'abc~1.png'
error: unable to add abc~1.png to index
fatal: adding files failed

我进行了反复试验,发现仅当波浪符号后跟数字时此错误仍然存​​在。

如果文件夹是第一次被 git 跟踪,其他文件也不会被 Git 跟踪。

$ git clean --dry-run
Would remove Rest.png
Would remove abc~1.png

请帮忙解决这个问题。

这是对 msys 进行更改的结果 Git in December 2014

On Windows' default filesystems, FAT and NTFS, DOS-style 8.3 file names are supported for backwards compatibility. That means that there are multiple ways to reference the same file. For example, the file credential-cache--daemon.c can also be accessed via CREDEN~1.C (unless another file has already been mapped to that so-called "short name", i.e. the exact short name is unpredictable).

Since this mapping is unpredictable, we need to disallow such file names on Windows, and while at it, we also exclude other file names incompatible with Windows' file systems (e.g. NUL, CON, etc).

We use the core.protectNTFS guard introduced in the previous commit to make sure that we prevent such file names only when appropriate.

要禁用此行为,您可以 运行:

git config core.protectNTFS false

但是,既然新行为是为了保护你,我建议 添加文件后将其改回:

git config core.protectNTFS true

仅当您需要在 命名或检查包含此类文件名的分支。

一般来说,我建议在工作时避免使用此类文件名 Windows 环境。