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

标签 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%

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

最佳答案

使用 ^ 转义有问题的 =

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/

相关文章:

string - Windows批处理文件中的IF条件下的“…”和x“…”之间有什么区别?

c++ - 将 2 个 int 值从子进程传递给父进程的方法

windows - FindFirstFile 多种文件类型

PHP stream_select 不起作用

swift - Xcode 6.3 中的 Git : Master branch showing new files from other branches in red and won't compile

git - 获取/pull 非常大的存储库的一部分?

python - 使用 Python 模块 main 函数进行验证测试是一个坏主意吗?

windows - 在 Windows 7 主机上使用事件 VPN 连接启动时,vagrant 配置的 virtualbox 无法访问互联网

git - 忽略来自 git repo 的 OSX stash 的 "._"文件

windows - 批量关机命令表现得像 sleep 命令,如何解决?