Skip to contentSkip to conversation

`git-rev-parse master` not referred to by any ref?

DISCUSSION J. Bruce Fields 3 participants 6 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Any idea how I got into this situation?:

	git$ git rev-parse master
	warning: refname 'master' is ambiguous.
	407c0c87e15b3cf60347f4fc0bcdb4d239de4163
	~/local/git$ git for-each-ref | grep master
	32ebe844c689d6e13e9875a0feefedca8dc1c6eb commit refs/heads/master
	e413074f1293e907d94af99330f0dd632a78b01f commit refs/remotes/linux-nfs/master
	0058a33a8eb5a8bfcfc5f5e769a2517cff4b73f1 commit refs/remotes/origin/master
	git$ git for-each-ref | grep 407c0
	git$ 

--b.

#1 lore raw
Quoted 11 lines · J. Bruce Fields

Any idea how I got into this situation?:

	git$ git rev-parse master
	warning: refname 'master' is ambiguous.
	407c0c87e15b3cf60347f4fc0bcdb4d239de4163
	~/local/git$ git for-each-ref | grep master
	32ebe844c689d6e13e9875a0feefedca8dc1c6eb commit refs/heads/master
	e413074f1293e907d94af99330f0dd632a78b01f commit refs/remotes/linux-nfs/master
	0058a33a8eb5a8bfcfc5f5e769a2517cff4b73f1 commit refs/remotes/origin/master
	git$ git for-each-ref | grep 407c0
	git$ 

Oops, found it:

	git$ cat .git/master
	407c0c87e15b3cf60347f4fc0bcdb4d239de4163

--b.

#2 lore raw
Quoted 13 lines · J. Bruce Fields
Quoted 11 lines · J. Bruce Fields

Any idea how I got into this situation?:

	git$ git rev-parse master
	warning: refname 'master' is ambiguous.
	407c0c87e15b3cf60347f4fc0bcdb4d239de4163
	~/local/git$ git for-each-ref | grep master
	32ebe844c689d6e13e9875a0feefedca8dc1c6eb commit refs/heads/master
	e413074f1293e907d94af99330f0dd632a78b01f commit refs/remotes/linux-nfs/master
	0058a33a8eb5a8bfcfc5f5e769a2517cff4b73f1 commit refs/remotes/origin/master
	git$ git for-each-ref | grep 407c0
	git$ 
Quoted 4 lines

Oops, found it:

	git$ cat .git/master
	407c0c87e15b3cf60347f4fc0bcdb4d239de4163

(Somebody on irc pointed out that

	git update-ref master 407c0c87e15b3cf60347f4fc0bcdb4d239de4163

The file's dated a couple weeks ago, so I don't remember, but I can easily imagine that I could have typed that assuming it'd update .git/refs/heads/master. OK!)

--b.

#3 lore raw
Quoted 4 lines · J. Bruce Fields
Quoted 4 lines

Oops, found it:

	git$ cat .git/master
	407c0c87e15b3cf60347f4fc0bcdb4d239de4163

It _might_ make it safer to refuse creating anything outside refs/ if the name does not contain or ends with "HEAD" (or perhaps names that have chars outside "[_A-Z]"), but that would restrict future tools that might want to have HEAD-like files, so I am a bit hesitant.

OTOH, a random file under .git/ does not count as a ref for the purposes of fsck/prune, so it may make sense to teach check_ref_format() about the same set of "special" names that can appear directly under .git without being in refs/ hierarchy (currently I think only "HEAD" and possibly "ORIG_HEAD" are in that set).

BTW, git-merge.sh and git-reset.sh should use "git update-ref ORIG_HEAD" instead of doing it by hand using "echo >$GIT_DIR/ORIG_HEAD".

Also, I *think* objects that are only reachable via ORIG_HEAD are not considered as reachable by fsck/prune --- we probably would want to fix this.

#4 lore raw
Quoted 3 lines · Junio C Hamano

Also, I *think* objects that are only reachable via ORIG_HEAD are not considered as reachable by fsck/prune --- we probably would want to fix this.

Probably. But most users also have reflog enabled on HEAD in the repository if they were to also have ORIG_HEAD there. In such a case ORIG_HEAD is usually HEAD@{1}, which is considered reachable by fsck/prune/repack.

Signature · 1 line
Shawn.
#5 lore raw
In reply to Junio C Hamano
Quoted 5 lines · Junio C Hamano

It _might_ make it safer to refuse creating anything outside refs/ if the name does not contain or ends with "HEAD" (or perhaps names that have chars outside "[_A-Z]"), but that would restrict future tools that might want to have HEAD-like files, so I am a bit hesitant.

Sure.

I would have recovered faster if I'd known had a simple way to get a list of all the refs that git-rev-parse finds. Is there an easy way? I assume "find .git -name .." will miss packed refs. Both git-show-ref and git-for-each-ref seem to ignore top-level references.

Maybe the "refname 'master' is ambiguous" warning could be modified to list the choices? I don't know if that would be overkill.

--b.