Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if git tag is some parent or child

Tags:

git

git-tag

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.

like image 839
Rainer Jung Avatar asked Dec 05 '25 07:12

Rainer Jung


1 Answers

  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.

like image 105
ElpieKay Avatar answered Dec 07 '25 21:12

ElpieKay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!