简体   繁体   English

.gitconfig文件中的Git别名错误

[英]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.

相关问题 "如何修复 Git for Windows 错误:“无法锁定配置文件 C:\/file\/path\/to\/.gitconfig: 文件存在”?" - How to fix Git for Windows error: "could not lock config file C:/file/path/to/.gitconfig: File exists"? 无法配置 git,缺少 .gitconfig 文件 - Can't configure git, missing .gitconfig file 存储库的.git或.gitconfig文件在哪里(如果存在)? - Where is, if it exists, a repo's .git or .gitconfig file? 强制Git使用特定的.gitconfig文件 - Forcing Git to use a specific .gitconfig file 错误:无法锁定配置文件 C:/Program Files/Git/mingw64/etc/gitconfig:权限被拒绝 - error: could not lock config file C:/Program Files/Git/mingw64/etc/gitconfig: Permission denied 错误:无法锁定配置文件 C:/Program Files/Git/mingw64/etc/.gitconfig: Permission denied - error: could not lock config file C:/Program Files/Git/mingw64/etc/.gitconfig: Permission denied 如何让别名在 .gitconfig 中工作? - How to get aliases working in .gitconfig? .gitconfig错误 - .gitconfig error 配置文件迁移后“Git 错误:无法锁定配置文件 C:/Users/old_profile/.gitconfig: No such file or directory” - “Git error: could not lock config file C:/Users/old_profile/.gitconfig: No such file or directory” after profile migration 是否可以阻止 git repo 使用全局 gitconfig 文件? - Is it possible to prevent a git repo from using the global gitconfig file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM