Determine latest received git tag

2020-07-22 09:01发布

问题:

I need to write an autoupdate script for our project. I have everything, except that I can't determine the name of the latest received tag. I tried with git describe, but it tells me the latest checked out tag. I don't need that of course, I have to get the next reachable tag to checkout. Any idea?

回答1:

Try this:

git describe --tags --abbrev=0 branch_name

to retrieve the name of the latest tag searching back from the tip of the desired branch, rather than HEAD (the current checkout).

That is, if your auto-update script has fetched origin master, you can do

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

Note: --abbrev=0 makes describe return only the tag name, without a sha1 at the end. --tags makes describe return the latest annotated or unannotated tag. See git-describe(1) for a full discussion of the possible options.



标签: git git-tag