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

标签 windows git batch-file delete-file

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

create file img

我试过.bat删除方式和dos del命令,还是不能删除名为cd ..
的文件 提示说找不到文件。文件大小属性为0字节。

file in explorer

如何删除这个文件?

最佳答案

我使用 cd .. 在 CMD Windows 中成功删除了“<path/to/git>\latest\usr\bin ”在 %PATH% .这让我可以访问 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 ..走了

作为commented通过 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”。
这将禁用所有字符串解析并将其后的字符串直接发送到文件系统。

关于windows - 找不到要通过 git bash 删除的文件,但它显示在文件资源管理器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45558587/

相关文章:

c# - "A first chance exception of type ' System.BadImageFormatException ' "在 64 位计算机上构建后

batch-file - 如果变量中有空格,带括号的 "if"不起作用

macros - 如何使用批处理文件打开并运行 Excel 宏

c++ - 将 SSH 编译成 C++ 应用程序

windows - 通过rsync或cp将文件发送到运行micropython的ESP32时,Windows上的Rshell随机卡住

c++ - 为什么不从入口点函数调用 FreeLibrary?

git - VS 代码 : explore commits in chronological order

裸存储库上的 git gc 不清理

git - 同一台机器上的多个 Git 用户

windows - 需要从 32 位和 64 位机器 Windows 机器读取注册表值