* List tags for a certain branch
@ 2015-08-23 15:27 CoDEmanX
2015-08-23 17:07 ` Jeff King
0 siblings, 1 reply; 4+ messages in thread
From: CoDEmanX @ 2015-08-23 15:27 UTC (permalink / raw)
To: git
Hi everyone,
the question how to list tags, that point to commits contained in a
certain branch came up on StackOverflow couple times, and this appears
to be the only fast solution (example for local devel branch):
git log --simplify-by-decoration --decorate --pretty=%d
"refs/heads/devel" | fgrep 'tag: '
It would be much much simpler, if the tag command supporter an optional
parameter to specify a branch:
git tag --list --branch devel
It should result in something like:
Test-Tag1
Test-Tag2
Test-Tag3
Another-Tag
And-Another
... even if all three Test-Tag* tags point to the same commit!
What above mentioned git log-solution does in this situtation is:
(HEAD, tag: Test-Tag1, tag: Test-Tag2, Test-Tag3, fork/devel, devel)
(tag: Another-Tag)
(tag: And-Another)
BTW: git describe FULL_HASH can't be used to return all tags that point
to the given hash. The only workaround seems to be:
git for-each-rev ref/tags | grep FULL_HASH
I hope you consider to add the proposed --branch option to a future git
version. Thanks!
SO question that started the discussion:
http://stackoverflow.com/questions/32166548/how-to-list-all-tags-within-a-certain-git-branch
Best,
Cody
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: List tags for a certain branch
2015-08-23 15:27 List tags for a certain branch CoDEmanX
@ 2015-08-23 17:07 ` Jeff King
2015-08-23 18:06 ` CoDEmanX
0 siblings, 1 reply; 4+ messages in thread
From: Jeff King @ 2015-08-23 17:07 UTC (permalink / raw)
To: CoDEmanX; +Cc: Karthik Nayak, git
On Sun, Aug 23, 2015 at 05:27:46PM +0200, CoDEmanX wrote:
> the question how to list tags, that point to commits contained in a certain
> branch came up on StackOverflow couple times, and this appears to be the
> only fast solution (example for local devel branch):
>
> git log --simplify-by-decoration --decorate --pretty=%d
> "refs/heads/devel" | fgrep 'tag: '
>
> It would be much much simpler, if the tag command supporter an optional
> parameter to specify a branch:
>
> git tag --list --branch devel
>
> It should result in something like:
>
> Test-Tag1
> Test-Tag2
> Test-Tag3
> Another-Tag
> And-Another
I think the option you are looking for is "--merged", which currently
only the "branch" command nows about. So right now you can do:
git branch --merged devel
to get a list of branches that are contained in "devel". There is work
underway to unify the selection/filter code for git-branch and git-tag,
so in a future version of git you should be able to do "git tag
--merged" to get the tags that are "merged" to a particular branch.
-Peff
PS I'm not sure if we should pick a more generic name than "--merged"
when git-tag learns this feature. For branches, it makes sense to ask
"which branches are merged to this other branch". But the operation is
really "which items are ancestors of the commit I gave". It is the
opposite of "--contains" in that sense. Sort of a "--contained-in".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: List tags for a certain branch
2015-08-23 17:07 ` Jeff King
@ 2015-08-23 18:06 ` CoDEmanX
2015-08-23 18:58 ` Jeff King
0 siblings, 1 reply; 4+ messages in thread
From: CoDEmanX @ 2015-08-23 18:06 UTC (permalink / raw)
To: git
> in a future version of git you should be able to do "git tag
--merged" to get the tags that are "merged" to a particular branch.
Would 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.
(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...)
I was able to achieve my goal with a Python script, that
- gets a list of all commit hashes for a given branch and creates a set
- creates a dictionary / hashmap from refs/tags/*, using commit hashes as keys and tag names as values
- creates a set from dictionary keys
- does an intersection operation using both sets
- and maps the remaining hashes back to tag names.
See the updated SO question:
http://stackoverflow.com/a/32169239/2044940
Thank you Peff!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: List tags for a certain branch
2015-08-23 18:06 ` CoDEmanX
@ 2015-08-23 18:58 ` Jeff King
0 siblings, 0 replies; 4+ messages in thread
From: Jeff King @ 2015-08-23 18:58 UTC (permalink / raw)
To: CoDEmanX; +Cc: git
On Sun, Aug 23, 2015 at 08:06:39PM +0200, CoDEmanX wrote:
> > in a future version of git you should be able to do "git tag
> --merged" to get the tags that are "merged" to a particular branch.
>
> Would 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.
>
> (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...)
Yes, it would show all tags that are present in the history leading up
to that branch tip[1]. Git tracks a DAG of the history; it does not
remember "which branch" a particular action happened on.
-Peff
[1] Actually the argument to "--merged" does not need to be a branch at
all. It is really a commit, so you could specify a tag, an extended
sha-1 expression, etc.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-08-23 18:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-23 15:27 List tags for a certain branch CoDEmanX
2015-08-23 17:07 ` Jeff King
2015-08-23 18:06 ` CoDEmanX
2015-08-23 18:58 ` Jeff King
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).