git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* Possible bug report: git checkout tag problem
@ 2018-01-08  3:50 Myles Fong
  2018-01-08 13:51 ` Johannes Schindelin
  0 siblings, 1 reply; 2+ messages in thread
From: Myles Fong @ 2018-01-08  3:50 UTC (permalink / raw)
  To: git

Hi,

Brief description:
When 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`

Expected behaviour:
I'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.

Found workaround:
If 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)

Affected version:
This happens with the latest git version 2.14.3.

Detailed background:
We 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.
I'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.

Related discussion:
I found this discussion to be related to the same problem:
https://stackoverflow.com/questions/30631000/git-checkout-tag-issues-tag-is-unchanged/30631434#30631434

Regards,
Myles Fong



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Possible bug report: git checkout tag problem
  2018-01-08  3:50 Possible bug report: git checkout tag problem Myles Fong
@ 2018-01-08 13:51 ` Johannes Schindelin
  0 siblings, 0 replies; 2+ messages in thread
From: Johannes Schindelin @ 2018-01-08 13:51 UTC (permalink / raw)
  To: Myles Fong; +Cc: git

Hi Myles,

On Mon, 8 Jan 2018, Myles Fong wrote:

> Brief description:
> When 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`
> 
> Expected behaviour:
> I'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.

The problem here is that Git understands something different from what you
intended: if you say `git checkout <commit-ish>`, Git is mostly interested
in the revision, i.e. the commit. Only if that parameter refers to a local
branch name (which is the only type of ref Git expects to advance via the
worktree) does it switch to a named branch. Otherwise it switches to what
I like to call "unnamed branch" (and which for historical reasons is
called "detached HEAD" by Git, something that is unlikely to be understood
without explicit explanation).

Now, as a convenience, Git tries to name the revision when it is on such
an unnamed branch. If a tag points to it, it uses the name of that tag to
describe it. If *multiple* tags point to it, it uses the newest one.

That's why you see what you see. It is intended behavior...

Ciao,
Johannes

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-08 13:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-08  3:50 Possible bug report: git checkout tag problem Myles Fong
2018-01-08 13:51 ` Johannes Schindelin

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.version-control.git
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.version-control.git
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git