{"thread":{"id":"47564","subject":"Possible bug report: git checkout tag problem","startedAt":"2018-01-08T03:50:27Z","lastAt":"2018-01-08T13:52:00Z","messageCount":2,"participants":["Myles Fong","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"336121","messageId":"160d3e3f291.df909f06277296.7997490218741761365@myles.hk","threadId":"47564","inReplyTo":null,"subject":"Possible bug report: git checkout tag problem","fromName":"Myles Fong","fromEmail":"i@myles.hk","sentAt":"2018-01-08T03:50:19Z","receivedAt":"2018-01-08T03:50:27Z","isPatch":false,"sender":{"key":"i@myles.hk","avatar":null},"body":"Hi,\n\nBrief description:\nWhen two tags are pointing to the same commit, e.g. tagA and tagB, if I do `git checkout tagA` then `git checkout tagB`,  and then `git status`, it shows `HEAD detached at tagA`\n\nExpected behaviour:\nI'm expecting it to show `HEAD detached at tagB`, though I understand this makes no difference for the repo code, but still a bit confusing for me.\n\nFound workaround:\nIf I do an extra step `git checkout master`, followed by `git checkout tagB`,  and then `git status`, it shows `HEAD detached at tagB` as expected. (\"master\" can be any branch name)\n\nAffected version:\nThis happens with the latest git version 2.14.3.\n\nDetailed background:\nWe have a system consists of many git repos, and are using tags of global version numbers to ensure the same version of repos are deployed in the whole system. Sometimes when we have a new minor version of the system, there is no new commits for some repos. Still we need a new version tag for those repos to match the system version number, so we put a new version tag pointing to the same commit as the previous version tag. This is how we ran into the above situation and I was suspecting that our deploying script didn't run properly when I see `HEAD detached at {old-version}` in some locations of a {new-version} system.\nI'm not sure if this is an expected behaviour or not because I didn't found any useful information after some Goolgling, except the following discussion.\n\nRelated discussion:\nI found this discussion to be related to the same problem:\nhttps://stackoverflow.com/questions/30631000/git-checkout-tag-issues-tag-is-unchanged/30631434#30631434\n\nRegards,\nMyles Fong\n\n\n"},{"id":"336141","messageId":"nycvar.QRO.7.76.6.1801081447350.31@ZVAVAG-6OXH6DA.rhebcr.pbec.zvpebfbsg.pbz","threadId":"47564","inReplyTo":"160d3e3f291.df909f06277296.7997490218741761365@myles.hk","subject":"Re: Possible bug report: git checkout tag problem","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-01-08T13:51:51Z","receivedAt":"2018-01-08T13:52:00Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Myles,\n\nOn Mon, 8 Jan 2018, Myles Fong wrote:\n\n> Brief description:\n> When two tags are pointing to the same commit, e.g. tagA and tagB, if I\n> do `git checkout tagA` then `git checkout tagB`,  and then `git status`,\n> it shows `HEAD detached at tagA`\n> \n> Expected behaviour:\n> I'm expecting it to show `HEAD detached at tagB`, though I understand\n> this makes no difference for the repo code, but still a bit confusing\n> for me.\n\nThe problem here is that Git understands something different from what you\nintended: if you say `git checkout <commit-ish>`, Git is mostly interested\nin the revision, i.e. the commit. Only if that parameter refers to a local\nbranch name (which is the only type of ref Git expects to advance via the\nworktree) does it switch to a named branch. Otherwise it switches to what\nI like to call \"unnamed branch\" (and which for historical reasons is\ncalled \"detached HEAD\" by Git, something that is unlikely to be understood\nwithout explicit explanation).\n\nNow, as a convenience, Git tries to name the revision when it is on such\nan unnamed branch. If a tag points to it, it uses the name of that tag to\ndescribe it. If *multiple* tags point to it, it uses the newest one.\n\nThat's why you see what you see. It is intended behavior...\n\nCiao,\nJohannes\n"}]}