Search code examples
gitgit-commit

Get the commit ID of the last tag in git history


I am on a commit which is not tagged. But there are tags in the commit history. So, following command gives me the latest release tag from the history

git describe --abbrev=0 --tags

Above outputs the tag like 1.15.21 which is good.
How can I get the commit ID that this tag was created on?


Solution

  • You can use git rev-parse to get the commit corresponding to a branch/tag

    git rev-parse HEAD
    abc123......
    

    So you can then pipe the output of your git describe using xargs

    git describe --abbrev=0 --tags | xargs git rev-parse
    def456.....