简体   繁体   中英

How to get individual elements of $ git describe?

We are working on a versioning system based on git tags. While git describe is great, we would prefer commands that output the three elements of git describe seperately (latest tag, commits since tag, commitId) eg TAG 12 gff9fd30 . We managed getting the commitId with git rev-parse HEAD , but don't know if there are any commands for only getting the latest tag and the commits since that tag.

Of course it would be possible to split the output at hyphens, but if there is a cleaner solution, we would prefer it.

Thanks for any hints!

only getting the latest tag

git describe --tags --abbrev=0

commits since that tag

git log LATEST_TAG..HEAD , you can use --pretty to format the logs.

Latest tag in the current branch:

git describe --tags --abbrev=0

(Found in https://stackoverflow.com/a/7261049/7976758 , search: https://stackoverflow.com/search?q=%5Bgit%5D+latest+tag )

Count commits since a commit:

git rev-list --count <revision>..

(Please note .. ; https://stackoverflow.com/a/4061706/7976758 , https://stackoverflow.com/search?q=%5Bgit%5D+count+commits ).

Overall:

git rev-list --count $(git describe --tags --abbrev=0)..

Or

lasttag=$(git describe --tags --abbrev=0)
git rev-list --count $lasttag..

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