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

Jen*_*och 2 windows git batch-file git-tag

我想在 Windows 上签出最新的 git 标签。

我在 Linux 上使用以下命令:

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

这个命令在 Windows 上的等价物是什么?


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

我开始于:

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

它返回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%
Run Code Online (Sandbox Code Playgroud)

如果你能想出一个单线,那就太好了。

wOx*_*xOm 5

使用^逃脱违规=

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