我如何打印我的git别名列表,即,类似于bash别名命令的东西?
当前回答
你可以在正则表达式^alias中使用——get-regexp,即所有以alias开头的配置
git config --get-regexp ^alias
其他回答
从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
只是添加这个,因为它太简单了,我在以前的答案中没有看到它(如果我错过了它,对不起)。
git help -a
你必须滚动到底部(使用>作为ma11hew28指出)来查看列表,例如:
Command aliases
restore-deleted !git restore $(git ls-files -d)
如果你甚至忘记了这个开关,一个简单的git帮助将帮助你记住:
'git help -a'和'git help -g'列出了可用的子命令 概念指南。参见'git help '或'git help ' 阅读一个特定的子命令或概念。
你可以创建一个别名来显示你机器上的所有git别名。运行下面的代码。
git config --global alias.alias "! git config --get-regexp ^alias\. | sed -e s/^alias\.// -e s/\ /\ =\ /"
然后,只需运行git别名。
这个回答是以约翰尼的回答为基础的。如果你不使用git-extras中的git-alias,它也适用。
在Linux上运行一次:
git config --global alias.alias "! git config --get-regexp ^alias\. | sed -e s/^alias\.// -e s/\ /\ =\ /"
这将创建一个名为alias的永久git别名,该别名将存储在~/中。gitconfig文件。使用它将列出所有的git别名,格式几乎与~/中的相同。gitconfig文件。要使用它,输入:
$ git alias
loga = log --graph --decorate --name-status --all
alias = ! git config --get-regexp ^alias\. | sed -e s/^alias\.// -e s/\ /\ =\ /
以下考虑因素适用:
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 command alias is but an alias and is not a feature of git. To sort the listed aliases, append | sort just before the closing double-quote. Alternatively, you can keep the aliases in ~/.gitconfig sorted. 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.
推荐文章
- 如何从终端/命令行调用VS代码编辑器
- 为什么在Mac OS X v10.9 (Mavericks)的终端中apt-get功能不起作用?
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- “你有邮件”的消息在终端,os X
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支