我如何打印我的git别名列表,即,类似于bash别名命令的东西?


当前回答

这个简单的解决方法对我来说很有效

为列出别名创建一个别名:) Git配置——全局别名。别名“config——get-regexp '^alias\.'” 执行它git aliases来列出我们所有其他的aliases

其他回答

有一个内置的功能…试一试

$ __git_aliases

列出所有的别名:)

你可以在正则表达式^alias中使用——get-regexp,即所有以alias开头的配置

git config --get-regexp ^alias

使用Bash列出全局和本地Git别名。即使没有安装Git,也可以正常工作。

$ cat ~/.gitconfig .git/config 2>/dev/null | sed -n '/alias/,/\[/p' | grep -v '^\['
        co = checkout
        br = branch
        ci = commit
        st = status

2>/dev/null -隐藏配置文件不存在时的错误 Sed -n '/alias/,/\[/p' -列出alias部分的内容 Grep -v '^\[' -隐藏部分标记(以左方括号开始)

相同命令的Bash别名

$ alias gita="cat ~/.gitconfig .git/config 2>/dev/null | sed -n '/alias/,/\[/p' | grep -v '^\['"

$ gita
        co = checkout
        br = branch
        ci = commit
        st = status

我喜欢@Thomas的回答,我做了一些修改。

特点:

添加颜色 和输入参数:让用户选择命令(从git配置——get-regexp ^.) 添加过滤器

# .gitconfig

[alias]
    show-cmd = "!f() { \
        sep="㊣" ;\
        name=${1:-alias};\
        echo -n -e '\\033[48;2;255;255;01m' ;\
        echo -n -e '\\033[38;2;255;0;01m' ;\
        echo "$name"; \
        echo -n -e '\\033[m' ;\
        git config --get-regexp ^$name\\..*$2+ | \
        cut -c 1-40 | \
        sed -e s/^$name.// \
        -e s/\\ /\\ $(printf $sep)--\\>\\ / | \
        column -t -s $(printf $sep) | \
        sort -k 1 ;\
    }; f"

使用

Git显示-cmd列表别名 Git show-cmd "" st列表别名,它应该包含字符串st Git show-cmd i18n show i18n设置 Git show-cmd核心编辑器显示核心设置,它应该包含编辑器

DEMO

它在窗户上也能正常工作

解释

you can write the long script on .gitconfig use the syntax as below: [alias] your-cmd = "!f() { \ \ }; f" name=${1:-alias} same as name = $1 if $1 else -alias echo -n -e (see more echo) -n = Do not output a trailing newline. -e Enable interpretation of the following backslash-escaped '\\033[38;2;255;0;01m' (see more SGR parameters) \\033[48; : 48 means background color. \\033[38;2;255;0;0m : 38 means fore color. 255;0;0 = Red cut -c 1-40 To avoid your command is too long, so take 40 char only. sed -e 's/be_replace_string/new_string/' replace string to new string. (if you want to put the special-char(such as space, > ...) should add \\ as the prefix. column -t -s $(printf $sep) formats all lines into an evenly spaced column table. sort -k 1 sorts all lines based on the value in the first column

如果您知道别名的名称,您可以使用——help选项来描述它。例如:

$ git sa --help
`git sa' is aliased to `stash'

$ git a --help
`git a' is aliased to `add'