Git: how to specify file names containing octal notation on the command line

前端 未结 1 523
长情又很酷
长情又很酷 2020-12-18 06:32

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

> git ls-files
\"\\337.txt\"

If su

相关标签:
1条回答
  • 2020-12-18 07:09

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

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

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


    Also, echo -e can do octal escaping:

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

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

    0 讨论(0)
提交回复
热议问题