我如何打印我的git别名列表,即,类似于bash别名命令的东西?
当前回答
如果您知道别名的名称,您可以使用——help选项来描述它。例如:
$ git sa --help
`git sa' is aliased to `stash'
$ git a --help
`git a' is aliased to `add'
其他回答
这个回答是以约翰尼的回答为基础的。如果你不使用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.
正如其他答案所提到的,git config -l列出了配置文件中的所有配置细节。下面是我的配置输出的部分示例:
...
alias.force=push -f
alias.wd=diff --color-words
alias.shove=push -f
alias.gitignore=!git ls-files -i --exclude-from=.gitignore | xargs git rm --cached
alias.branches=!git remote show origin | grep \w*\s*(new^|tracked) -E
core.repositoryformatversion=0
core.filemode=false
core.bare=false
...
所以我们可以grep掉别名行,使用git config -l | grep alias:
alias.force=push -f
alias.wd=diff --color-words
alias.shove=push -f
alias.gitignore=!git ls-files -i --exclude-from=.gitignore | xargs git rm --cached
alias.branches=!git remote show origin | grep \w*\s*(new^|tracked) -E
我们可以通过删除别名来使它更漂亮。每一行的一部分,留给我们这样的命令:
git config -l | grep alias | cut -c 7-
打印:
force=push -f
wd=diff --color-words
shove=push -f
gitignore=!git ls-files -i --exclude-from=.gitignore | xargs git rm --cached
branches=!git remote show origin | grep \w*\s*(new^|tracked) -E
最后,不要忘记添加这个作为别名:
git config --global alias.la "!git config -l | grep alias | cut -c 7-"
享受吧!
另一种选择(纯粹是我觉得容易记住的东西):
Git配置——list | grep别名
这个简单的解决方法对我来说很有效
为列出别名创建一个别名:) Git配置——全局别名。别名“config——get-regexp '^alias\.'” 执行它git aliases来列出我们所有其他的aliases
搜索或显示所有别名
在[alias]下添加到你的.gitconfig:
aliases = !git config --list | grep ^alias\\. | cut -c 7- | grep -Ei --color \"$1\" "#"
然后你就可以
git aliases -显示所有aliases Git别名commit -仅包含“commit”的别名
推荐文章
- 如何从终端/命令行调用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拉另一个分支