Search code examples
gitcommand-linegit-describe

git describe show only latest tag and additional commits


Is there any syntax for git describe to display only the latest tag and additional commits?

So that you get

4.0.7 for being at the commit tagged 4.0.7
4.0.7-12 for having 12 commits since tag 4.0.7

git describe --tags is pretty close with 4.0.7-12-g09181 but i haven't found a way to get rid of the hash being appended.

git describe --tags --abbrev=2

still displays 4.0.7-12-g0918

git describe --tags --abbrev=0

displays 4.0.7 only.


Solution

  • There is no option in the describe command to do what you want. You could pipe the output to a shell script that removes the hash.

    git describe --tags | sed 's/\(.*\)-.*/\1/'
    

    see https://stackoverflow.com/a/32084572/1468708

    thx !