无法添加名称中包含代字号的文件,后跟一个数字“〜” [英] Unable to add files with name containing tilde, '~' followed by a number

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

问题描述

该文件夹包含文件名,如 abc〜1 123〜1 a1d2〜3



当我做 git add --all

  $ git add --all 
错误:无效路径'abc〜1.png'
错误:无法添加abc〜1.png来索引
fatal:添加文件失败

我做了一个试验和错误,我发现这个错误只有在波形符号后跟一个数字时才会持续存在。



如果第一次使用git跟踪文件夹,其他文件也没有被Git跟踪。

  $ git clean --dry-run 
将删除Rest。 png
会删除abc〜1.png

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

解决方案

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


On W indows的默认文件系统,FAT和NTFS,DOS风格的8.3文件名是
,用于向后兼容。这意味着有多个
的方式来引用同一个文件。例如,文件
credential-cache-daemon.c也可以通过CREDEN〜1.C访问(除非
另一个文件已经映射到所谓的短名称,即
确切的短名称是不可预知的)。

因为这个映射是不可预知的,所以我们需要在
Windows上禁止这样的文件名,而在我们也排除了与
Windows文件系统不兼容的其他文件名(例如NUL,CON等)。

我们使用core.protectNTFS guard引入在之前的提交中,我们确信只有在适当的时候才阻止这样的文件名。


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

  git config core.protectNTFS false 

然而,由于新的行为是为了保护你,所以我建议
在添加文件后将其改回:

  git config core.protectNTFS true 

只有当您需要在
名称中添加带有波形符号的文件时才禁用此保护,或者查看包含此类文件名的分支。



一般来说,如果在
a Windows环境下工作,我建议避免使用这些文件名。


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

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.

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.

解决方案

This is the result of a change that was made to 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.

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.

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

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

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