While going through renaming of tags , I came to know that anotated tags are object themselves having their own SHA1 id's. HERE
I also know how git checkout
resolves their references. HERE
If $GIT_DIR/ exists, that is what you mean (this is usually useful only for HEAD, FETCH_HEAD, ORIG_HEAD, MERGE_HEAD and CHERRY_PICK_HEAD);
otherwise, refs/ if it exists;
otherwise, refs/tags/ if it exists;
otherwise, refs/heads/ if it exists;
otherwise, refs/remotes/ if it exists;
otherwise, refs/remotes//HEAD if it exists.
Now my question is when I do git checkout some_annotated_tag_name
or even git checkout SHA1_ID_OF_ANNOTATED_TAG
it switches my HEAD to the commit which annotated tag points to and not to the object of annotated tag.
What is the reason behind this ? If I am mentioning some SHA1 ID , it should take me to that SHA1 Id ?
EDIT : Let us say my annotated tag name is annot
. It's SHA1 is 216a2ee6ef4276566081c6dc1ee853bfd1798829
and the SHA1 of the commit it points to is a8b21d7a46903e90d08338fd0311e2ead8d86eac
.
Now let use see what result we get.
git checkout annot
Output :
Note: checking out 'annot'.
You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at a8b21d7... 3rd
git checkout 216a2ee6ef4276566081c6dc1ee853bfd1798829
Output :
Note: checking out '216a2ee6ef4276566081c6dc1ee853bfd1798829'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at a8b21d7... 3rd