对于文件名中的非ASCII字符,Git将以八进制表示法输出它们。例如:
> git ls-files
"\337.txt"
如果这样的字节序列不表示合法的编码(对于命令行的当前编码),则无法在命令行上输入相应的String。我如何仍然在这些文件上调用Git命令?显然,使用git ls-files
显示的字符串不起作用:
> git rm "\337.txt"
fatal: pathspec '337.txt' did not match any files
[已在Windows上测试,使用msysgit 1.7.10(git版本1.7.10.msysgit.1)
在Bash中,您可以将printf
用于这种目的:
printf
显然,问题是外壳程序不执行八进制转义,而git也没有。但是$ printf "\337.txt"
▒.txt
$ git rm `printf "\337.txt"` # this would pass the awkward filename to git
可以。
此外,printf
可以进行八进制转义:
echo -e
但是这种用法有点不鼓励,您应该尽可能选择$ echo -e '\0337.txt'
▒.txt
。