2

I have a few tags in my Git repo:

  • release/20-000RC1
  • release/21-000RC1
  • release/22-000RC1

First I check out release/20-000RC1:


git checkout release/20-000RC1
git status

HEAD detached at release/20-000RC1

Status properly shows release/20-000RC1


Then I check out release/21-000RC1:

git checkout release/21-000RC1
git status

HEAD detached at release/21-000RC1

Status properly shows release/21-000RC1


Now finally I checkout release/22-000RC1, and...

git checkout release/22-000RC1
git status

HEAD detached at release/21-000RC1
nothing to commit, working directory clean

Instead of release/22-000RC1 "git status" shows me release/21-000RC1.

I'm very confused about why after doing checkout of release/22-000RC1 it stays on 21-000RC1 when doing status?

2
  • when my edit lands, please check the question. Is this what you do and see? Do you really merge to develop? You didn't mention it. Jun 3, 2015 at 21:39
  • Hi Nick. The merge is not the issue, but rather the fact that I do "git checkout release/22-000RC1" and then when I do "git status" it tells me that I'm on release/21-000RC1. Thanks. Jun 3, 2015 at 21:43

2 Answers 2

2

The merge is not the issue, but rather the fact that I do "git checkout release/22-000RC1" and then when I do "git status" it tells me that I'm on release/21-000RC1.

Run the following commands. They will show sha1-s of commits, connected to these tags. Are outputs equal?

git rev-parse release/21-000RC1
git rev-parse release/22-000RC1

If they are equal, then tags are on the same commit. You checkout to release/22-000RC1, which is a commit tagged with release/21-000RC1, and that tag was created earlier, so its name is shown instead.

You can use the following command to list all tags, pointing to the current commit.

git tag --points-at HEAD
5
  • git cat-file showed me that they do point to the same thing. This is very strange to me though, if I tell git to move the tag to a specific one, I'd expect it to actually do just that, even if tag points to the same commit as another tag. Is there any way to force git to change the current tag when status is ran, even if the old one points to same commit? Jun 3, 2015 at 21:55
  • You should delete 22-tag on this commit and then tag some other commit with 22. Jun 3, 2015 at 21:58
  • Can't do that, I need the tags to be there for history... There's a chance that I will have several tags pointing to the same commit. Jun 3, 2015 at 22:00
  • Looks like I'm out of luck here and this is just one of git's design peculiarities.... Thanks. Jun 3, 2015 at 22:10
  • Let us continue this discussion in chat. Jun 3, 2015 at 22:11
0

Are you checking out release/20-000RC1 or are you checking out the git hash f425ed7? If you're checking out the git hash, you aren't on the branch. "Detached head" is a pretty traumatic message, but it merely says "hey, put a branch label here so you don't lose your work."

5
  • Well, it's not about losing work. Just "no branch here". Jun 3, 2015 at 21:26
  • If you git checkout something else, and wait a few weeks, git gc (run automatically with just about everything else) will delete the nodes, presuming they're abandoned.
    – robrich
    Jun 3, 2015 at 21:28
  • the key is "abandoned". Tags are not abandoned anyway, they're tagged. Indeed, I agree that "detached HEAD" is not something bad. Jun 3, 2015 at 21:32
  • The problem is not detached head, which is expected when you check out a tag. My problem is that after I check out release/22-000RC1 my git status tells me that I'm on release/21-000RC1. Jun 3, 2015 at 21:41
  • 1
    do both tags point to the same commit? did git checkout return a non-zero exit status?
    – robrich
    Jun 4, 2015 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.