具有 shell 变量扩展的 Git 别名
我想在 git 别名内使用 shell 变量扩展来去除分支的前缀。不幸的是,当我使用“标准”别名时,变量扩展没有完成:
publish = push -u origin ${$(git symbolic-ref HEAD)##refs/heads/}
这是试图实际推送一个名为“${$(git”)的分支。但是如果我将别名更改为:
publish = "!git push -u origin ${$(git symbolic-ref HEAD)##refs/heads/}"
它通过 sh 运行并且无法执行我想要替换有什么解决方法吗?
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/}"
it's run via sh and fails to do the substitution I want. Is there some workaround?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试更改
为
This 使用
sh
反引号执行命令,并使用sed
进行正则表达式替换。Try changing
to
This uses
sh
backticks to execute commands andsed
to do the regular expression substitution.低级解释:
${xxx}
语法始终需要 xxx 的变量名称。它不会替换任意字符串。要使用 ##,必须:x=$(git symbolic-ref HEAD);回声 ${x##refs/heads/};
Low-level explanation: The
${xxx}
syntax always requires a variable name for xxx. It does not substitute an arbitrary string. To use ##, one would have to:x=$(git symbolic-ref HEAD); echo ${x##refs/heads/};