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


当前回答

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

其他回答

你可以在正则表达式^alias中使用——get-regexp,即所有以alias开头的配置

git config --get-regexp ^alias

我创建了一个git别名(奇怪的是)别名正是为了这个目的…如果你经常使用混叠的话,会很方便。

$ git配置——全局别名。别名“config -get-regexp ^ Alias \.”

注意,regex确保行以别名开始。

$ 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

windows:

git config --list | findstr "alias"

有一个内置的功能…试一试

$ __git_aliases

列出所有的别名:)