无法通过 git bash 找到要删除的文件,但它显示在文件资源管理器中

Cannot find file to delete via git bash, but it shows up in file explorer

我昨天开始学习git,我在创建ssh密钥时出错,如第一张图所示。

我试过.bat删除方式和dos del命令,还是无法删除名为cd ..
的文件 提示说 cannot find file。文件大小属性为0字节

如何删除这个文件?

查看文件的属性。在那里你可以找到文件位置。转到该位置并从那里删除。

并查看它是哪种类型的文件。我的意思是,它可能是系统文件,如果是,系统将不允许您删除它。以管理员身份打开资源管理器,然后尝试删除它。

我设法删除了 CMD Windows 中的“cd ..”,在 %PATH% 中删除了 <path/to/git>\latest\usr\bin。这让我可以访问 rm.exe.

vonc@VONCAVN7 C:\test
> where rm
D:\prgs\git\latest\usr\bin\rm.exe

我有:

vonc@VONCAVN7 C:\test
> dir /x
 Volume in drive C is test

 Directory of C:\test

08/08/2017  07:11    <DIR>                       .
08/08/2017  07:11    <DIR>                       ..
08/08/2017  07:11                 0              cd ..

有了这个,我输入了:

vonc@VONCAVN7 C:\test
> rm cd*

文件cd ..不见了

by eryksun

rm.exe isn't a Linux app. It uses msys-2.0.dll, which links with Windows API functions from kernel32.dll and native NT system calls from ntdll.dll.
In this case it's how it bypasses the Windows API to make direct system calls that solves the problem: NtOpenFile (open the directory to list it and the "cd .." file to delete it), NtQueryDirectoryFile (list the directory), and NtSetInformationFile (set the file's delete disposition).


正如 eryksun 评论的那样,纯 Windows 语法(意思是,它不需要像 rm 这样的 Git Linux 之类的命令)也工作过:

del "\?\C:\test\cd .."

参见“What does \?\ mean when prepended to a file path”。
这将禁用所有字符串解析并将其后的字符串直接发送到文件系统。