I have an issue when i'm trying to check out a different tag on the same commit.
This becomes an issue in an application where i check where the detached head is at.
I believe this is because the commit is tagged with both 4.1 and 4.1.1 but i need the head to explicitly say "HEAD detached at 4.1" when i'm checking out tags/4.1 from the 4.1.1 tag not display the same "HEAD detached at 4.1.1" text.
Unable to update detached head from 4.1 -> 4.1.1
Unable to update detached head from 4.1.1 -> 4.1
In the last checkout i cannot switch from 4.1 to 4.1.1, probably because the HEAD is already at the commit, is there someway to force the "HEAD detached at N" without like checking out the master branch in this case and then checking out the tag.
Since this is supposed to be used in production when there might be a few users online i want the checkout to be as smooth and clear (where the head is detached) as possible.


TL;DR: apparently, you would have to cheat. I don't recommend doing this, but show how it would work, below.
More or less, yes. It's more accurate to say that "switching" from 4.1 to 4.1.1 is not switching anything at all, because 4.1 and 4.1.1 are the same commit. Git takes a shortcut and does not write anything at all, because nothing needs to be written. Well, that is, except:
The "detached at / from" that
git statusreports is based on a bread-crumb trail left behind in theHEADreflog. When you rungit checkout Xfor some X and Git updatesHEAD, Git first saves the current value ofHEADinto the reflog forHEAD, along with a comment, such as this one:(
puis the "proposed update" or "pickup" branch in the Git repository for Git itself, so the above entry is the result of me doinggit checkout pu, which createdpufromorigin/puand gave it the value8265814db9543fbaf50c4db8133671ce64dc1ae4, and thengit checkout master. The motion from master to the newly createdpumadeHEAD@{1}, whose comment ischeckout: moving from master to pu.)When
HEADis detached, whatgit statusdoes is to root through the reflog forHEADto try to find which branch or tag you had explicitly checked-out before you got to whatever commit you are on right now. If the detached-HEAD commit you are on right now matches the value of that branch or tag name, you aredetached at Ywhere Y comes from the comment. If the detached-HEAD commit you are on right now doesn't match (or maybe is not@{0}),git statusreportsdetached from Yinstead ofdetached at Y.So, if you could get the reflog updated, you could get
git statusto report something new. The obvious way to do that isgit update-ref, but I tried it. Here is what happened. First, we set up the situation:and of course
git statusreports "detached at v2.18.0". So:Alas,
git update-refalso took a short-cut and did not bother to update the reflog. (Perhaps thegit checkout hahadid invoke the reflog update code, but that took the shortcut.) So, it's time to cheat—note that I'm not advising that anyone actually do this!—by knowing that a HEAD reflog update just adds a line to.git/logs/HEAD:The
$t$command duplicated the last line; then$s/from master to v2.18.0/from v2.18.0 to haha/replaced the comment with a new comment. So nowgit statusreports what we want it to report.It's pretty clearly a bug that
git update-refshort-circuits the update. It might also be an important or useful optimization, but if so, there should be some flag to enable the optimization or force the update, based on whichever default is deemed more important. The bug would be irrelevant except for this wholegit statusrelies on the reflog thing.