列出 Git 别名 [英] List Git aliases
问题描述
如何打印我的 git 别名列表,即类似于 bash alias
命令的内容?
How do I print a list of my git aliases, i.e., something analogous to the bash alias
command?
推荐答案
此答案建立在 answer 的基础上 href="https://stackoverflow.com/users/880767/johnny">约翰尼.如果您不使用 git-alias
来自 git-extras
.
This answer builds upon the answer by johnny. It applies if you're not using git-alias
from git-extras
.
在 Linux 上,运行一次:
On Linux, run once:
git config --global alias.alias "! git config --get-regexp ^alias. | sed -e s/^alias.// -e s/ / = /"
这将创建一个名为 alias
的永久 git 别名,它存储在您的 ~/.gitconfig
文件中.使用它将列出所有 git 别名,格式与 ~/.gitconfig
文件中的格式几乎相同.要使用它,请输入:
This will create a permanent git alias named alias
which gets stored in your ~/.gitconfig
file. Using it will list all of your git aliases, in nearly the same format as they are in the ~/.gitconfig
file. To use it, type:
$ git alias
loga = log --graph --decorate --name-status --all
alias = ! git config --get-regexp ^alias. | sed -e s/^alias.// -e s/ / = /
以下注意事项适用:
为了防止别名
alias
被列在上面,附加|grep -v ^'alias '
就在结束双引号之前.我不建议这样做,所以用户不要忘记命令alias
只是一个别名,而不是 git 的功能.
To prevent the alias
alias
from getting listed as above, append| grep -v ^'alias '
just before the closing double-quote. I don't recommend this so users don't forget that the the commandalias
is but an alias and is not a feature of git.
要对列出的别名进行排序,请附加 |在结束双引号之前排序
.或者,您可以将 ~/.gitconfig
中的别名保持排序.
To sort the listed aliases, append | sort
just before the closing double-quote. Alternatively, you can keep the aliases in ~/.gitconfig
sorted.
要将别名添加为系统范围的别名,请将 --global
(对于当前用户)替换为 --system
(对于所有用户).这通常位于 /etc/gitconfig
文件中.
To add the alias as a system-wide alias, replace --global
(for current user) with --system
(for all users). This typically goes in the /etc/gitconfig
file.
这篇关于列出 Git 别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!