Git:如何在命令行中指定包含八进制符号的文件名 [英] Git: how to specify file names containing octal notation on the command line

查看:293
本文介绍了Git:如何在命令行中指定包含八进制符号的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于文件名中的非ASCII字符,Git将以八进制符号输出。例如:

For non-ASCII characters in file names, Git will output them in octal notation. For example:

> git ls-files
"\337.txt"

如果这样一个字节序列不代表合法编码(对于命令行的当前编码),我无法在命令行中输入相应的字符串。我仍然可以在这些文件上调用Git命令?显然,使用 git ls-files 显示的字符串不起作用:

If such a byte sequence does not represent a legal encoding (for the command line's current encoding), I'm not able to enter the corresponding String on command line. How can I still invoke Git commands on these files? Obviously, using the String which is displayed by git ls-files does not work:

> git rm "\337.txt"
fatal: pathspec '337.txt' did not match any files

在Windows上测试,使用msysgit 1.7.10(git版本1.7.10.msysgit.1)

Tested on Windows, with msysgit 1.7.10 (git version 1.7.10.msysgit.1)

推荐答案

在Bash中,您可以使用 printf 为此目的:

In Bash, you can use printf for this kind of purpose:

$ echo `printf "\337.txt"`
▒.txt

$ git rm `printf "\337.txt"`  # this would pass the awkward filename to git

问题是,显然,shell不执行八进制转义,git也不执行。但是 printf

The problem is, obviously, that the shell doesn't perform octal escaping, neither does git. But printf does.

另外, echo -e 可以执行八进制转义:

Also, echo -e can do octal escaping:

$ echo -e '\0337.txt'
▒.txt

但是这种用法有点不鼓励,你应该更喜欢 printf 你可以在哪里。

But that usage is a bit discouraged, you should prefer printf where you can.

这篇关于Git:如何在命令行中指定包含八进制符号的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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