[英]Git aliases error in .gitconfig file
I've been using this alias: 我一直在使用这个别名:
aliases = !git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /'
to show all aliases in the config file. 以显示配置文件中的所有别名。
but it's messy - I wanted to add a color to the alias name, before the "=" sign. 但这很麻烦-我想在别名“ =”之前添加颜色。 So I added some color:
所以我加了一些颜色:
aliases = !git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /' | awk '{printf "\033[1;31m" $1 "\033[0m"; $1=""; print $0;}'
it works great when I use the command from the CLI, but when I try to put it in the .gitconfig file it throws an error. 当我使用CLI中的命令时,它工作得很好,但是当我尝试将其放在.gitconfig文件中时,它将引发错误。 something to do with the quotation marks.
与引号有关。 I tried to escape them, but to no avail...
我试图逃脱他们,但无济于事...
How can I get the alias to work? 如何获得别名?
There seem to be some quoting problems. 似乎存在一些引用问题。 I suggest a dedicated shell script because quoting makes it quite unreadable.
我建议使用专用的Shell脚本,因为引号会使它变得不可读。 With less separate processes:
使用较少的独立过程:
git-color-aliases 混帐色,别名
#!/bin/sh
git config --get-regexp 'alias.*' | awk '{printf "\033[1;31m%s\033[0m = ", substr($1,7); $1=""; print $0}'
.gitconfig 的.gitconfig
aliases = color-aliases
I gave it a try and it works by just quoting the whole string: 我尝试了一下,只引用了整个字符串就可以了:
alias2 = !"git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /'"
You can have a great help to debug your config by using trace like that: 您可以使用以下跟踪信息来调试配置,这将为您提供很大的帮助:
GIT_TRACE=1 git alias2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.