[英]In Git is it possible to refer an alias from another alias
Let say I have an alias like this in my .gitconfig:假设我的 .gitconfig 中有一个这样的别名:
alias.showlog = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
and now I want a similar alias like this:现在我想要一个类似的别名:
alias.sl = showlog --abbrev-commit
When I try the command git sl
it say he does not know the showlog
command.当我尝试命令git sl
它说他不知道showlog
命令。
I know it is still possible to copy the same command like the other alias, but I just want to know if there is any possibility to refer another alias in an alias?我知道仍然可以像其他别名一样复制相同的命令,但我只想知道是否有可能在别名中引用另一个别名?
In versions of Git before 2.20:在 2.20 之前的 Git 版本中:
Not that way, but you can make an alias run a command through the shell, hence running another instance of git
which resolves the second alias:不是那样,但是您可以让别名通过 shell 运行命令,从而运行另一个git
实例来解析第二个别名:
alias.sl = !git showlog --abbrev-commit
In 2.20 or later, see VonC's answer .在 2.20 或更高版本中,请参阅VonC 的回答。
Update Q4 2018: Yes, it is possible possible with Git 2.20: an alias that expands to another alias has so far been forbidden, but now it is allowed to create such an alias. 2018 年第四季度更新:是的,Git 2.20 是可能的:到目前为止,禁止扩展为另一个别名的别名,但现在允许创建这样的别名。
See commit fef5f7f , commit 82f71d9 , commit c6d75bc (16 Sep 2018) by Tim Schumacher ( timschumi
) .请参阅Tim Schumacher ( timschumi
) 的commit fef5f7f 、 commit 82f71d9 、 commit c6d75bc (2018 年 9 月 16 日) 。
(Merged by Junio C Hamano -- gitster
-- in commit 506ee60 , 16 Oct 2018) (由Junio C gitster
合并gitster
提交 506ee60,2018年 10 月 16 日)
alias
: add support for aliases of an aliasalias
: 添加对别名别名的支持
Aliases can only contain non-alias git commands and their arguments, not other user-defined aliases.别名只能包含非别名的 git 命令及其参数,不能包含其他用户定义的别名。 Resolving further (nested) aliases is prevented by breaking the loop after the first alias was processed.通过在处理第一个别名后中断循环,可以防止解析更多(嵌套)别名。
Git then fails with a command-not-found error.然后 Git 失败并出现 command-not-found 错误。
Allow resolving nested aliases by not breaking the loop in
run_argv()
after the first alias was processed.允许通过在处理第一个别名后不中断run_argv()
的循环来解析嵌套别名。
Instead, continue the loop untilhandle_alias()
fails, which means that there are no further aliases that can be processed.相反,继续循环直到handle_alias()
失败,这意味着没有可以处理的其他别名。 Prevent looping aliases by storing substituted commands incmd_list
and checking if a command has been substituted previously.通过将替换命令存储在cmd_list
并检查之前是否已替换命令来防止循环别名。
So... this will be possible now:所以......现在这将是可能的:
git config alias.nested-internal-1 nested-internal-2
git config alias.nested-internal-2 status
git nested-internal-1
That would be a git status
.那将是一个git status
。
With Git 2.30 (Q1 2021), the command line completion script (in contrib/) learned to expand commands that are alias of alias.在 Git 2.30(2021 年第一季度)中,命令行完成脚本(在 contrib/ 中)学会了扩展别名别名的命令。
See commit e4c75ed (12 Nov 2020), and commit c2822a8 , commit 9414938 (09 Nov 2020) by Felipe Contreras ( felipec
) .请参阅Felipe Contreras ( felipec
) 的commit e4c75ed (12 Nov 2020) 和commit c2822a8 、 commit 9414938 (09 Nov 2020 ) 。
(Merged by Junio C Hamano -- gitster
-- in commit fd6445a , 25 Nov 2020) (由Junio C gitster
-- gitster
--在提交 fd6445a 中合并,2020 年 11 月 25 日)
completion
: bash: support recursive aliasescompletion
:bash:支持递归别名Signed-off-by: Felipe Contreras签字人: Felipe Contreras
It is possible to have recursive aliases like:可能有递归别名,例如:
l = log --oneline lg = l --graph
So the completion should detect such aliases as well.所以完成也应该检测这样的别名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.