Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible with Git to retrieve a list of tags that exist only in a certain branch?

Tags:

git

branch

tags

I would like to know if it's possible in Git to retrieve a list of tags (much like the result of the git tag command), but the list should be limited only to a certain branch.

If this is possible, can anyone explain how this is done? Perhaps with some pattern-matching magic?

like image 531
Wolfgang Schreurs Avatar asked May 15 '12 14:05

Wolfgang Schreurs


People also ask

Are git tags specific to a branch?

It is important to understand that tags have no direct relationship with branches - they only ever identify a commit. That commit can be pointed to from any number of branches - i.e., it can be part of the history of any number of branches - including none.

How do you get tags from a branch?

Find Latest Git Tag Available In order to find the latest Git tag available on your repository, you have to use the “git describe” command with the “–tags” option. This way, you will be presented with the tag that is associated with the latest commit of your current checked out branch.

Which command is used to list tags in git?

Listing the available tags in Git is straightforward. Just type git tag (with optional -l or --list ). You can also search for tags that match a particular pattern. The command finds the most recent tag that is reachable from a commit.

Does git fetch include tags?

git fetch --tags fetches all tags, all commits necessary for them. It will not update branch heads, even if they are reachable from the tags which were fetched.


2 Answers

Another approach would be possible with the new git tag options --merged (in git 2.7+, Q4 2015)

git tag --merged <abranchname>

See commit 5242860, ... (10 Sept 2015) by Karthik Nayak (KarthikNayak).
(Merged by Junio C Hamano -- gitster -- in commit 8a54523, 05 Oct 2015)

tag.c: implement '--merged' and '--no-merged' options

Use 'ref-filter' APIs to implement the '--merged' and '--no-merged' options into 'tag.c'.

  • The '--merged' option lets the user to only list tags merged into the named commit.
  • The '--no-merged' option lets the user to only list tags not merged into the named commit.

If no object is provided it assumes HEAD as the object.

like image 86
VonC Avatar answered Oct 06 '22 21:10

VonC


I think this will do what you want:

 git log --pretty='%H' <branch> |
   xargs -n1 git describe --tags --exact-match 2>/dev/null

This uses git log to get a list of commits in a branch, and then passes them to git describe to see if they correspond to a tag.

like image 29
larsks Avatar answered Oct 06 '22 20:10

larsks