【问题标题】:How do I remove a git branch whose name starts with a unicode character?如何删除名称以 unicode 字符开头的 git 分支?
【发布时间】:2020-09-02 11:24:43
【问题描述】:

使用 GfW 我不小心创建了一个名称以 <U+0096> 开头的分支,这似乎是一个 unicode 控制字符。

$ git branch
  features/#72_some_branch
* features/#73_another_branch
  master
  <U+0096>features/#73_another_branch

现在,为了纠正这个错误,我需要知道如何在 git bash 中转义它。我尝试使用众所周知的 Alt+Num 组合键,但没有奏效。

【问题讨论】:

    标签: git git-bash git-for-windows


    【解决方案1】:

    我不得不承认,答案很明显。使用 bash shell 的内置 echo 命令,我能够插入所需的符号:

    git branch -d "$(echo -e '\u0096')features/#73_another_branch"
    

    【讨论】:

    • 这是一个有用的结果
    • 所以不能直接"\u0096features..."
    • 我也试过这种方法,但没有奏效。似乎 git-bash 不会自行对这些字符进行分隔。就我而言,它说error: branch '\u0096features/#73_another_branch' not found.
    • @MadPhysicist:这里有一个 shell 语法很有用,但有点奇怪。也不是所有的 shell 都实现了它。使用$'text',您可以让shell 展开某些转义:\t 成为制表符,\r 成为回车符,等等。这里只允许进行八进制扩展,但对于 \u0096,您需要 $'\226'(八进制 226 = 十进制 = 150 = 0x96)。
    • 我以前从未见过这种语法,所以我立即对其进行了测试。似乎这会发出另一种字符。也许这确实使用了另一个字符集,甚至是八进制以外的数字?
    猜你喜欢
    • 2020-02-28
    • 2020-02-20
    • 2010-09-05
    • 1970-01-01
    • 2016-03-17
    • 2014-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多