I have the SHA ID of a commit that I am interested in and would like to know how to find the first tag that contains it.
The commands show a reference to the commit built on a tag plus a
~$n ancestorhood count - they return the most recent tag that contains a commit. To remove the ancestorhood count pipe the result to sed:
<command> | sed 's/~.*//'
If there is no tag that contains this commit, git describe will fail.
inspec on master ➜ git name-rev --tags --name-only 175c3e1189ac2520ebc705db438bed50cd569892 v1.49.7~1
inspec on master ➜ git describe --contains 175c3e1189ac2520ebc705db438bed50cd569892 v1.49.7~1