Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git, detect that local HEAD is pointing to a GIT tag

Tags:

git

How can I detect if the actual working was checked based on a tag?

Let's say I'm performing the following GIT command:

 > git checkout 1.2.3

git status tells me that me my HEAD "pointer" is in a detached state. This could also be the case if I checkout SHA directly, e.g. via:

 > git checkout f1d96551ab404de047c846a0a59f76e8505046c9 

How can I find out that HEAD is actually pointing to a commit, which has a tag on it?

Thx

like image 677
Moerwald Avatar asked Oct 21 '25 17:10

Moerwald


2 Answers

git tag --points-at HEAD

It lists the tags that are pointing at the HEAD commit.

If the tag 1.2.3 points at f1d96551ab404de047c846a0a59f76e8505046c9 and you want to find out if the detached HEAD was caused by git checkout 1.2.3 or git checkout f1d96551ab404de047c846a0a59f76e8505046c9, run git reflog.

like image 111
ElpieKay Avatar answered Oct 24 '25 07:10

ElpieKay


Whether your HEAD points directly (detached) to a tagged commit or to a branch whose tip is tagged,

git describe

would output the exact name of the tag ONLY IF it points to it directly, otherwise it will be suffixed by -<numberOfCommitsSinceTag>-g<commitHash>

But as a sidenote, HEAD can't point to a tag. It always point to a branch or a commit.

(Also, in case your repo tags are of the unannotated type, use the --tags flag for describe.)

like image 31
Romain Valeri Avatar answered Oct 24 '25 07:10

Romain Valeri



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!