我如何打印我的git别名列表,即,类似于bash别名命令的东西?
当前回答
$ 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 2.18开始,你可以使用git——list-cmds=alias
我在2018年6月提到“概述列表-最常用的git命令”,git 2.18“使用——list-cmds=alias (commit 3301d36)”,carej在他的回答中报告。
git --list-cmds=alias
除此之外,或者git config——get-regexp别名,你可以将它的输出与git帮助结合起来,它的输出将在git 2.14.x/2.15中发生变化:
“git help co”现在说“co is alias to…”,而不是“git co is”。
参见Kaartic Sivaraam提交b3a8076(2017年9月12日)。 (由Junio C Hamano—gitster—在commit 5079cc8中合并,2017年9月25日)
帮助:将信息更改为更精确的信息 当用户尝试在一个别名命令上使用'——help'选项时,关于别名的信息将打印如下所示:
$ git co --help
`git co' is aliased to `checkout'
这似乎是不正确的,因为用户只有'co'而不是'git co'的别名。 在用户使用了'tgit'这样的别名的情况下,这甚至可能是不正确的。
$ tgit co --help
`git co' is aliased to `checkout'
我在全局的~/.gitconfig中使用这个别名
# ~/.gitconfig
[alias]
aliases = !git config --get-regexp ^alias\\. | sed -e s/^alias.// -e s/\\ /\\ $(printf \"\\043\")--\\>\\ / | column -t -s $(printf \"\\043\") | sort -k 1
产生以下输出
$ git aliases
aliases --> !git config --get-regexp ^alias\. | sed -e s/^alias.// -e s/\ /\ $(printf "\043")--\>\ / | column -t -s $(printf "\043") | sort -k 1
ci --> commit -v
cim --> commit -m
co --> checkout
logg --> log --graph --decorate --oneline
pl --> pull
st --> status
... --> ...
(注意:这适用于我在Windows上的git bash。对于其他终端,您可能需要调整转义。)
解释
!git config --get-regexp ^alias\\. prints all lines from git config that start with alias. sed -e s/^alias.// removes alias. from the line sed -e s/\\ /\\ $(printf \"\\043\")--\\>\\ / replaces the first occurrence of a space with \\ $(printf \"\\043\")--\\> (which evaluates to #-->). column -t -s $(printf \"\\043\") formats all lines into an evenly spaced column table. The character $(printf \"\\043\") which evaluates to # is used as separator. sort -k 1 sorts all lines based on the value in the first column
美元(printf \“\ 043 \”)
这只是打印用于列分隔的字符#(十六进制043)。我使用这个小hack,所以别名本身不字面上包含#字符。否则,它将在打印时替换这些#字符。 注意:如果您需要使用#符号的别名,请将此更改为另一个字符。
使用git var,只过滤那些以alias开头的:
git var -l | grep -e "^alias"
如果您知道别名的名称,您可以使用——help选项来描述它。例如:
$ git sa --help
`git sa' is aliased to `stash'
$ git a --help
`git a' is aliased to `add'
推荐文章
- 为什么git-rebase给了我合并冲突,而我所做的只是压缩提交?
- 当我试图推到原点时,为什么Git告诉我“没有这样的远程‘原点’”?
- 如何强制从另一个SSH会话分离屏幕?
- 如何从远程分支中挑选?
- 如何从终端机发送电子邮件?
- 如何查看一个分支中的哪些提交不在另一个分支中?
- 如何取消在github上的拉请求?
- HEAD和master的区别
- GIT克隆在windows中跨本地文件系统回购
- RPC失败;卷度传输已关闭,剩余未完成的读取数据
- 我应该在.gitignore文件中添加Django迁移文件吗?
- 错误:您对以下文件的本地更改将被签出覆盖
- Git rebase—即使所有合并冲突都已解决,仍然会继续报错
- 在Git中,我如何知道我的当前版本是什么?
- 跟踪所有远程git分支作为本地分支