我如何打印我的git别名列表,即,类似于bash别名命令的东西?


当前回答

windows:

git config --list | findstr "alias"

其他回答

这个回答是以约翰尼的回答为基础的。如果你不使用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.

使用Bash列出全局和本地Git别名。即使没有安装Git,也可以正常工作。

$ cat ~/.gitconfig .git/config 2>/dev/null | sed -n '/alias/,/\[/p' | grep -v '^\['
        co = checkout
        br = branch
        ci = commit
        st = status

2>/dev/null -隐藏配置文件不存在时的错误 Sed -n '/alias/,/\[/p' -列出alias部分的内容 Grep -v '^\[' -隐藏部分标记(以左方括号开始)

相同命令的Bash别名

$ alias gita="cat ~/.gitconfig .git/config 2>/dev/null | sed -n '/alias/,/\[/p' | grep -v '^\['"

$ gita
        co = checkout
        br = branch
        ci = commit
        st = status

使用git var,只过滤那些以alias开头的:

git var -l | grep -e "^alias"

windows:

git config --list | findstr "alias"

只是添加这个,因为它太简单了,我在以前的答案中没有看到它(如果我错过了它,对不起)。

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 ' 阅读一个特定的子命令或概念。