如何在 Windows 上获取最新的 git 标签?

How to get the latest git tag on Windows?

我想查看 Windows 上的最新 git 标签。

我在 Linux 上使用以下命令:

git checkout `git describe --tags --abbrev=0 origin/master`

此命令在 Windows 上的等效项是什么?


我尝试使用 forset 将带反引号的命令扩展为一个变量,以便在 git checkout.

上使用

我开始时:

for /f %a in ('git describe') do (echo %a).

它returns v1.0.18-131-g792d5a2。这有效,但包含的信息太多了。我只需要v1.0.18。这就是为什么我试图使用 --abbrev=<n> 来抑制长格式并只显示最接近的标签。

当我添加参数时:

for /f %a in ('git describe --tags --abbrev=0 origin/master') do (echo %a)

它失败了:fatal: Not a valid object name 0。不知道为什么...


这是我目前得到的:

checkout-latest-tag.bat

@echo off

for /f "usebackq delims=" %%a in ('git describe --tags --abbrev=0 origin/master') do (
   set LATEST_TAG=%%a
)
echo The latest tag is: %LATEST_TAG%

git checkout %LATEST_TAG%

如果你能想出一条线就好了。

使用^ 逃避冒犯=

for /f %%a in ('git describe --tags --abbrev^=0 origin/master') do git checkout %%a