无法添加名称包含波浪号、“~"后跟数字的文件 [英] Unable to add files with name containing tilde, '~' followed by a number

查看:17
本文介绍了无法添加名称包含波浪号、“~"后跟数字的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文件夹由文件名如 abc~1123~1a1d2~3 的文件组成.

The folder consists of files with filenames like abc~1, 123~1, a1d2~3.

当我执行 git add --all 时,它说,

When I do git add --all it says,

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

我进行了反复试验,发现只有当波浪号后面跟有数字时,此错误才会持续存在.

I did a trial and error and I found this error persists only when the tilde symbol is followed by a number.

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

If the folder is tracked by git for the first time, the other files are also not tracked by Git.

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

请帮助我如何解决此问题.

Please help how do I fix this issue.

推荐答案

这是对 msys Git 进行更改的结果 2014 年 12 月.

This is the result of a change that was made to msys Git in December 2014.

在 Windows 的默认文件系统、FAT 和 NTFS 上,DOS 风格的 8.3 文件名是支持向后兼容.这意味着有多个引用同一个文件的方法.例如,文件credential-cache--daemon.c 也可以通过 CREDEN~1.C 访问(除非另一个文件已经映射到所谓的短名称",即确切的简称是不可预测的).

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).

由于这个映射是不可预测的,我们需要禁止这样的文件名Windows,在此过程中,我们还排除了与不兼容的其他文件名Windows 的文件系统(例如 NUL、CON 等).

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).

我们使用上次提交中引入的core.protectNTFS guard来做确保我们仅在适当的时候阻止此类文件名.

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

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

To disable this behaviour, you can run:

git config core.protectNTFS false

但是,由于新行为是为了保护您,我建议您添加文件后将其改回:

However, since the new behaviour is there to protect you, I’d recommend changing it back after having added your files:

git config core.protectNTFS true

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

Only disable this protection when you need to add files with tildes in the name or check out branches containing such filenames.

一般来说,如果在以下环境中工作,我建议避免使用此类文件名Windows 环境.

In general, I’d recommend avoiding such filenames if working in a Windows environment.

这篇关于无法添加名称包含波浪号、“~"后跟数字的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆