具有shell变量扩展的Git别名

问题描述:

我想在git别名中使用shell变量扩展去除分支的前缀。不幸的是,当我使用标准别名时,变量扩展没有完成:

I'd like to use a shell variable expansion inside of a git alias to strip a prefix of a branch. Unfortunately when I use the "standard" alias, variable expansion is not done:

publish = push -u origin ${$(git symbolic-ref HEAD)##refs/heads/}

这是试图实际推送一个分支如果我把别名改成:

This is trying to actually push a branch called "${$(git". But if I change the alias to:

publish = "!git push -u origin ${$(git symbolic-ref HEAD)##refs/heads/}"

sh并且没有做到我想要的替换。是否有一些解决方法?

it's run via sh and fails to do the substitution I want. Is there some workaround?

尝试更改

!git push -u origin ${$(git symbolic-ref HEAD)##refs/heads/}

!git push -u origin `git symbolic-ref HEAD | sed -e "s#^refs/heads/##"`

这使用 sh 反引号执行命令, sed 执行正则表达式替换。

This uses sh backticks to execute commands and sed to do the regular expression substitution.