git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] checkout: allow full refnames for local branches

From
LHLars Hjemli <hjemli@gmail.com>
Date
May 9, 2007, 19:55 UTC
Message-ID
<8c5c35580705091255v2f85db3qcbf65904c278d17@mail.gmail.com>
In-Reply-To
<7v8xbxu6u0.fsf@assigned-by-dhcp.cox.net>
On 5/9/07, Junio C Hamano <junkio@cox.net> wrote:
Show 30 quoted lines
> "Lars Hjemli" <hjemli@gmail.com> writes:
>
> > On 5/9/07, Junio C Hamano <junkio@cox.net> wrote:
> >> Lars Hjemli <hjemli@gmail.com> writes:
> >>
> >> > This teaches git-checkout to strip the prefix 'refs/heads/' from the
> >> > supplied <branch> argument
> >>
> >> Why is this necessary, may I ask?
> >>
> >
> > I'm playing around with a gui frontend, and there I use
> > git-for-each-ref to obtain possible arguments for git-checkout. That's
> > how I discovered the 'problem', and solved it by stripping
> > 'refs/heads/' in my frontend.
>
> Pathspec-less variant of "git checkout" takes two kinds of
> parameters and has two flavours in its behaviour:
>
>  (1) an exact branch name, in which case it switches to the
>      branch; otherwise
>
>  (2) any arbitrary commit object name, in whch case it checks
>      out and detaches HEAD.
>
> A tricky part is that an exact branch name is often a perfectly
> valid commit object name, so rule (1) trumps the rule (2).  You
> just discovered a way to have a detached HEAD at a commit that
> happens to be at an existing branch -- by naming that commit
> without using its exact branch name.

Ok. But if this is intended behaviour, maybe we would want do change the detach-message in this case:

[~/src/git] next$ git checkout refs/heads/master
Note: moving to "refs/heads/master" which isn't a local branch

(sorry for stealing your time with this unimportant stuff, it just surprised me that refs/heads/$branch wasn't treated as a local branch name)

-- 
larsh
Previous: Junio C Hamano
Message 9 of 9 in “checkout: allow full refnames for local branches”
  1. checkout: allow full refnames for local branchesLars Hjemli, May 9, 2007
  2. Junio C HamanoMay 9, 2007
  3. Lars HjemliMay 9, 2007
  4. Shawn O. PearceMay 9, 2007
  5. Lars HjemliMay 9, 2007
  6. Shawn O. PearceMay 9, 2007
  7. Lars HjemliMay 9, 2007
  8. Junio C HamanoMay 9, 2007
  9. Lars HjemliMay 9, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.