Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: list dangling tags

Context:

  • assume you have some rather tricky CI/CD workflow which relies on git tags
  • the feature branches are built and generate some short-lived tags to signify commits which yield the deployable artifacts
  • when the feature branch gets squash-merged, usually it's deleted, but the tags, unsurprisingly, survive
  • after, say, several months of development the tag listing predictably becomes hairy

Hence, the question:

how would I, using git command line and, optionally, basic bash tooling

  1. list all the branches which have given tag reachable (the dual to that is git tag -l --merged ${BRANCH_COMMITTISH}, but I need not tags for the given branch but branches for a given tag)
  2. list all the tags which have empty output from point 1 above (obviously this is doable with a for loop (given any terminating implementation for 1), but maybe there's some neat magical git one-liner)?
like image 954
Anton Kraievyi Avatar asked Jul 31 '18 13:07

Anton Kraievyi


2 Answers

git log --simplify-by-decoration --tags --not --branches --remotes --pretty=%d

--simplify-by-decoration says only show the bare minimum needed to reveal the ancestry (usually you use this with --graph). --tags --not --branches --remotes says, well, what it says: list the tag history that's not in the branches or remotes history, i.e. tags unreachable from any branch or remote-tracking branch. --pretty=%d says just show the refs.

like image 156
jthill Avatar answered Sep 21 '22 02:09

jthill


  1. git branch --contains ${TAG}

https://git-scm.com/docs/git-branch#git-branch---containsltcommitgt.

like image 36
phd Avatar answered Sep 21 '22 02:09

phd