简体   繁体   中英

How to get the latest git tag on Windows?

I want to checkout the latest git tag on Windows.

I use the following command on Linux:

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

Whats the equivalent for this command on Windows?


I tried using for & set to expand the backticked command into a variable for usage on the git checkout .

I started out with:

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

It returns v1.0.18-131-g792d5a2 . This works, but contains a bit too much information. I just need v1.0.18 . That's why i'm trying to use --abbrev=<n> to suppress the long format and only show the closest tag.

When i added the arguments:

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

it fails with: fatal: Not a valid object name 0 . Not sure why...


Here is what i got so far:

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%

It would be nice, if you could come up with a one-liner.

使用^来逃避犯罪=

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM