Reputation: 11294
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
Upvotes: 4
Views: 1963
Reputation: 4263
List all tags which reference HEAD
git tag --points-at HEAD
Check if a specific tag (or one tag which matches pattern) is referenced by HEAD or another <commit-ish>
git describe --exact-match --match foo/tag-name-xyz
git describe --exact-match --match foo/tag-name-xyz HEAD~5
git describe --exact-match --match foo/tag-name-*
git describe
will list zero or one tag, if there are multiple tags on a <commit-ish>
that match, seems like it picks the first ASCII sorted
Upvotes: 0
Reputation: 30888
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
.
Upvotes: 6
Reputation: 22017
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
.)
Upvotes: 3