如何在 Git 中为标签添加别名?

Ben*_*ngt 5 git shell aliases subcommand

我有一个 Git 命令别名来从存储库中查看最新标签:

~/.gitconfig:

checkout-latest = !git checkout $(git describe --tags `git rev-list --tags --max-count=1`)
Run Code Online (Sandbox Code Playgroud)

所以我可以在正确标记的存储库中使用它,如下所示:

$ git checkout-latest
Run Code Online (Sandbox Code Playgroud)

我有 checkout 命令的命令别名:

~/.gitconfig:

co = checkout
Run Code Online (Sandbox Code Playgroud)

不适checkout-latest用于结帐命令别名:

$ git co-latest
git: 'co-latest' is not a git command. See 'git --help'.
Run Code Online (Sandbox Code Playgroud)

如何配置 Git,以便可以使用latest 作为指向以编程方式确定的最新标签的标签别名?我想这样使用它:

$ git checkout latest
Run Code Online (Sandbox Code Playgroud)

$ git co latest
Run Code Online (Sandbox Code Playgroud)

请注意,在我想要的变体中,子命令和标签之间没有破折号

Kev*_*ger 0

Git 别名不能引用其他别名。

但是,您可以通过另一层间接来完成此操作:

co-latest = !git checkout-latest "$@"
Run Code Online (Sandbox Code Playgroud)