{"thread":{"id":"40161","subject":"List tags for a certain branch","startedAt":"2015-08-23T15:27:46Z","lastAt":"2015-08-23T18:58:23Z","messageCount":4,"participants":["CoDEmanX","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"268531","messageId":"55D9E672.4050503@gmx.de","threadId":"40161","inReplyTo":null,"subject":"List tags for a certain branch","fromName":"CoDEmanX","fromEmail":"codemanx@gmx.de","sentAt":"2015-08-23T15:27:46Z","receivedAt":"2015-08-23T15:27:46Z","isPatch":false,"sender":{"key":"codemanx@gmx.de","avatar":null},"body":"Hi everyone,\n\nthe question how to list tags, that point to commits contained in a \ncertain branch came up on StackOverflow couple times, and this appears \nto be the only fast solution (example for local devel branch):\n\n     git log --simplify-by-decoration --decorate --pretty=%d \n\"refs/heads/devel\" | fgrep 'tag: '\n\nIt would be much much simpler, if the tag command supporter an optional \nparameter to specify a branch:\n\n     git tag --list --branch devel\n\nIt should result in something like:\n\nTest-Tag1\nTest-Tag2\nTest-Tag3\nAnother-Tag\nAnd-Another\n\n... even if all three Test-Tag* tags point to the same commit!\n\nWhat above mentioned git log-solution does in this situtation is:\n\n  (HEAD, tag: Test-Tag1, tag: Test-Tag2, Test-Tag3, fork/devel, devel)\n  (tag: Another-Tag)\n  (tag: And-Another)\n\n\nBTW: git describe FULL_HASH can't be used to return all tags that point \nto the given hash. The only workaround seems to be:\n\n     git for-each-rev ref/tags | grep FULL_HASH\n\n\nI hope you consider to add the proposed --branch option to a future git \nversion. Thanks!\n\nSO question that started the discussion:\n\nhttp://stackoverflow.com/questions/32166548/how-to-list-all-tags-within-a-certain-git-branch\n\nBest,\nCody\n"},{"id":"268532","messageId":"20150823170751.GA24194@sigill.intra.peff.net","threadId":"40161","inReplyTo":"55D9E672.4050503@gmx.de","subject":"Re: List tags for a certain branch","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-08-23T17:07:52Z","receivedAt":"2015-08-23T17:07:52Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Aug 23, 2015 at 05:27:46PM +0200, CoDEmanX wrote:\n\n> the question how to list tags, that point to commits contained in a certain\n> branch came up on StackOverflow couple times, and this appears to be the\n> only fast solution (example for local devel branch):\n> \n>     git log --simplify-by-decoration --decorate --pretty=%d\n> \"refs/heads/devel\" | fgrep 'tag: '\n> \n> It would be much much simpler, if the tag command supporter an optional\n> parameter to specify a branch:\n> \n>     git tag --list --branch devel\n> \n> It should result in something like:\n> \n> Test-Tag1\n> Test-Tag2\n> Test-Tag3\n> Another-Tag\n> And-Another\n\nI think the option you are looking for is \"--merged\", which currently\nonly the \"branch\" command nows about. So right now you can do:\n\n  git branch --merged devel\n\nto get a list of branches that are contained in \"devel\". There is work\nunderway to unify the selection/filter code for git-branch and git-tag,\nso in a future version of git you should be able to do \"git tag\n--merged\" to get the tags that are \"merged\" to a particular branch.\n\n-Peff\n\nPS I'm not sure if we should pick a more generic name than \"--merged\"\nwhen git-tag learns this feature. For branches, it makes sense to ask\n\"which branches are merged to this other branch\". But the operation is\nreally \"which items are ancestors of the commit I gave\". It is the\nopposite of \"--contains\" in that sense. Sort of a \"--contained-in\".\n"},{"id":"268538","messageId":"0322fd40-7473-4faa-840f-8be27f555435@email.android.com","threadId":"40161","inReplyTo":"20150823170751.GA24194@sigill.intra.peff.net","subject":"Re: List tags for a certain branch","fromName":"CoDEmanX","fromEmail":"codemanx@gmx.de","sentAt":"2015-08-23T18:06:39Z","receivedAt":"2015-08-23T18:06:39Z","isPatch":false,"sender":{"key":"codemanx@gmx.de","avatar":null},"body":"> in a future version of git you should be able to do \"git tag \n--merged\" to get the tags that are \"merged\" to a particular branch. \n\nWould it return every tag in the branch, even if it was created in that branch, and not merged from somewhere else? If no, than it's not what I am looking for. \n\n(Or more precisely: would it give a list of all tags, that point to commits present in the specified branch, regardless of whether these commits were originally done in that branch or merged from another branch? I hope my understanding of git is correct here...)\n\nI was able to achieve my goal with a Python script, that\n\n- gets a list of all commit hashes for a given branch and creates a set\n- creates a dictionary / hashmap from refs/tags/*, using commit hashes as keys and tag names as values\n- creates a set from dictionary keys\n- does an intersection operation using both sets\n- and maps the remaining hashes back to tag names.\n\nSee the updated SO question:\n\nhttp://stackoverflow.com/a/32169239/2044940\n\nThank you Peff!"},{"id":"268543","messageId":"20150823185822.GA8005@sigill.intra.peff.net","threadId":"40161","inReplyTo":"0322fd40-7473-4faa-840f-8be27f555435@email.android.com","subject":"Re: List tags for a certain branch","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-08-23T18:58:23Z","receivedAt":"2015-08-23T18:58:23Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Aug 23, 2015 at 08:06:39PM +0200, CoDEmanX wrote:\n\n> > in a future version of git you should be able to do \"git tag \n> --merged\" to get the tags that are \"merged\" to a particular branch. \n> \n> Would it return every tag in the branch, even if it was created in\n> that branch, and not merged from somewhere else? If no, than it's not\n> what I am looking for. \n> \n> (Or more precisely: would it give a list of all tags, that point to\n> commits present in the specified branch, regardless of whether these\n> commits were originally done in that branch or merged from another\n> branch? I hope my understanding of git is correct here...)\n\nYes, it would show all tags that are present in the history leading up\nto that branch tip[1]. Git tracks a DAG of the history; it does not\nremember \"which branch\" a particular action happened on.\n\n-Peff\n\n[1] Actually the argument to \"--merged\" does not need to be a branch at\n    all. It is really a commit, so you could specify a tag, an extended\n    sha-1 expression, etc.\n"}]}