Reputation: 21
I have a repository HELPER and about 350 tags created on it. I am on 'master' branch and want to checkout a tag for read-only purpose.
When i do checkout, it says it is pointing to some sha1 id which not the sha1 of that tag.
here is the snippet,
bash-4.1$ git checkout **HELPER_F62.3.REL**
HEAD is now at **7e04dfb**... *HELPER_OS4.1.35*
bash-4.1$ git show-ref **HELPER_F62.3.REL**
**d722076d24ec9d13d845094181f47801ca77b4ca** refs/tags/HELPER_F62.3.REL
bash-4.1$ git show-ref HELPER_OS4.1.35
2782a48d2044b0fc0aa60ecf2823967a2312e1dd refs/tags/HELPER_OS4.1.35
I do not want to create a new branch, and I am fine with the detached HEAD as i use this repo as a read-only repo.
Currently on git version 1.8.0-rc0
Upvotes: 1
Views: 724
Reputation: 489638
I suspect you have an annotated tag. When you use git checkout
to detach HEAD
and get on the corresponding commit, you see the commit-ID rather than the annotated tag's ID.
You can see this with, e.g., git show-ref --deref
:
$ git show-ref --deref master annotag
a430f6d91b98d382b8d96f6812fc2056a6e6f678 refs/heads/master
20e14672ee2253d38c1001179d8f17688d47059c refs/tags/annotag
a430f6d91b98d382b8d96f6812fc2056a6e6f678 refs/tags/annotag^{}
shows that branch master
(which I tagged with git tag -a annotag
to create an annotated tag) is where annotag
resolves once de-referenced, even though annotag
points to a separate git object.
(Lightweight tags point directly at commits, and are unchanged under --deref
.)
If you just want to get the annotated tag's hash ID, or just want to get the target of the tag, use git rev-parse
, like this:
$ git rev-parse annotag
2e79bc84c11eda5d73add5a9dfc6bf03c50c432d
$ git rev-parse annotag^{}
676699a0e0cdfd97521f3524c763222f1c30a094
Note that the ^{}
suffix means follow the tag to whatever object it locates. If the tag locates a tree or blob object, rather than a commit, the hash ID you get from the above is that of the tree or blob. If you want to be sure that it is a commit, use the ^{commit}
suffix notation:
$ git rev-parse annotag^{commit}
676699a0e0cdfd97521f3524c763222f1c30a094
If the commit points to some other kind of object than the one specified in the braces, you get an error:
$ git rev-parse annotag^{tag}
2e79bc84c11eda5d73add5a9dfc6bf03c50c432d
$ git rev-parse annotag^{blob}
error: annotag^{blob}: expected blob type, but the object dereferences to tree type
[more error messages, snipped]
These syntaxes (syntaces? syntagma?) are described in the gitrevisions documentation (q.v.).
Upvotes: 2