我如何打印我的git别名列表,即,类似于bash别名命令的东西?
当前回答
从git 2.18开始,你可以使用git——list-cmds=alias
其他回答
我喜欢@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'
$ git alias -h
'alias' is aliased to '!git config --list | grep 'alias\.' | sed
's/alias\.\([^=]*\)=\(.*\)/\1\ => \2/' | sort'
a => !git add . && git status
aa => !git add . && git add -u . && git status
ac => !git add . && git commit
acm => !git add . && git commit -m
正如其他答案所提到的,git config -l列出了配置文件中的所有配置细节。下面是我的配置输出的部分示例:
...
alias.force=push -f
alias.wd=diff --color-words
alias.shove=push -f
alias.gitignore=!git ls-files -i --exclude-from=.gitignore | xargs git rm --cached
alias.branches=!git remote show origin | grep \w*\s*(new^|tracked) -E
core.repositoryformatversion=0
core.filemode=false
core.bare=false
...
所以我们可以grep掉别名行,使用git config -l | grep alias:
alias.force=push -f
alias.wd=diff --color-words
alias.shove=push -f
alias.gitignore=!git ls-files -i --exclude-from=.gitignore | xargs git rm --cached
alias.branches=!git remote show origin | grep \w*\s*(new^|tracked) -E
我们可以通过删除别名来使它更漂亮。每一行的一部分,留给我们这样的命令:
git config -l | grep alias | cut -c 7-
打印:
force=push -f
wd=diff --color-words
shove=push -f
gitignore=!git ls-files -i --exclude-from=.gitignore | xargs git rm --cached
branches=!git remote show origin | grep \w*\s*(new^|tracked) -E
最后,不要忘记添加这个作为别名:
git config --global alias.la "!git config -l | grep alias | cut -c 7-"
享受吧!
使用git var,只过滤那些以alias开头的:
git var -l | grep -e "^alias"
推荐文章
- 为什么git-rebase给了我合并冲突,而我所做的只是压缩提交?
- 当我试图推到原点时,为什么Git告诉我“没有这样的远程‘原点’”?
- 如何强制从另一个SSH会话分离屏幕?
- 如何从远程分支中挑选?
- 如何从终端机发送电子邮件?
- 如何查看一个分支中的哪些提交不在另一个分支中?
- 如何取消在github上的拉请求?
- HEAD和master的区别
- GIT克隆在windows中跨本地文件系统回购
- RPC失败;卷度传输已关闭,剩余未完成的读取数据
- 我应该在.gitignore文件中添加Django迁移文件吗?
- 错误:您对以下文件的本地更改将被签出覆盖
- Git rebase—即使所有合并冲突都已解决,仍然会继续报错
- 在Git中,我如何知道我的当前版本是什么?
- 跟踪所有远程git分支作为本地分支