我如何打印我的git别名列表,即,类似于bash别名命令的东西?
当前回答
另一个git别名(称为alias)打印出git别名:添加以下到你的gitconfig [alias]部分:
[alias]
# lists aliases matching a regular expression
alias = "!f() { git config --get-regexp "^alias.${1}$" ; }; f"
示例用法,给出完整的别名(与别名完全匹配:即^foobar$),并简单地显示值:
$ git alias st
alias.st status -s
$ git alias dif
alias.dif diff
或者,给regexp,它会显示所有匹配的别名和值:
$ git alias 'dif.*'
alias.dif diff
alias.difs diff --staged
alias.difh diff HEAD
alias.difr diff @{u}
alias.difl diff --name-only
$ git alias '.*ing'
alias.incoming !git remote update -p; git log ..@{u}
alias.outgoing log @{u}..
注意:引用regexp以防止将shell扩展为glob,尽管如果/当没有文件匹配该模式时,在技术上并不需要这样做。另外:任何regexp都可以,除了不能使用^(模式开始)和$(模式结束);它们是隐含的。假设您没有使用git-extras中的git-alias。
而且,显然你们的别名也会有所不同;这些只是我配置的几个。(也许你也会发现它们很有用。)
其他回答
如果您知道别名的名称,您可以使用——help选项来描述它。例如:
$ git sa --help
`git sa' is aliased to `stash'
$ git a --help
`git a' is aliased to `add'
打开。gitconfig文件(C:\Users\user.gitconfig)—Windows 在[别名]下复制并粘贴以下代码 别名= !git config——list | grep ^别名\\。| cut -c 7- | grep - ei——color \"$1\" "#" 在终端git alias——列出所有别名 在终端git别名commit——列出所有与提交相关的别名 获得所有别名的列表,而不记得代码:)
使用git var,只过滤那些以alias开头的:
git var -l | grep -e "^alias"
这个简单的解决方法对我来说很有效
为列出别名创建一个别名:) Git配置——全局别名。别名“config——get-regexp '^alias\.'” 执行它git aliases来列出我们所有其他的aliases
我喜欢@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
推荐文章
- RPC失败;卷度传输已关闭,剩余未完成的读取数据
- 我应该在.gitignore文件中添加Django迁移文件吗?
- 错误:您对以下文件的本地更改将被签出覆盖
- Git rebase—即使所有合并冲突都已解决,仍然会继续报错
- 在Git中,我如何知道我的当前版本是什么?
- 跟踪所有远程git分支作为本地分支
- 自定义SSH端口上的Git
- git如何显示不存在于.gitignore中的未跟踪文件
- Git错误:遇到7个文件应该是指针,但不是
- GitHub克隆与OAuth访问令牌
- 移动(或“撤销”)最后一个git提交到非暂存区域
- 我可以在GitHub上对要点进行拉请求吗?
- Hg:如何做一个像git的rebase
- 如何丢弃远程更改并将文件标记为“已解决”?
- 如何查看远程标签?