我想在 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%
如果你能想出一条线就好了。
最佳答案
使用 ^
转义有问题的 =
。
for /f %%a in ('git describe --tags --abbrev^=0 origin/master') do git checkout %%a
关于windows - 如何在 Windows 上获取最新的 git 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32886626/