Rainer Jung
Rainer Jung

Reputation: 740

Check if git tag is some parent or child

Is there a way to find out if a tag is a child or parent (not the direct child or parent)?

Imagine the following git history:

a467066 - (tag: child-2, master) feature 4
2028351 - (tag: child-1) feature 3
a7a6364 - (HEAD) feature 2
3772445 - (tag: parent-1) feature 1
5a01bfa - (tag: parent-2) initial commit

My HEAD is in the middle changeset ("feature 2") and I want to know if a tag is any child to the current changeset. So for child-1 and child-2 I want a true, checking the tags parent-1, parent-2 or any not-existing would return false.

Upvotes: 3

Views: 1959

Answers (1)

ElpieKay
ElpieKay

Reputation: 30878

  1. git tag --contains HEAD

    It lists all the tags that are descendants of HEAD

  2. git merge-base <tag> <HEAD>

    If it returns the commit of HEAD, then tag is a descendant of HEAD.

  3. git merge-base --is-ancestor <tag> <HEAD>

    If tag is an ancestor of HEAD, the command's exit status is 0.

Upvotes: 5

Related Questions