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

Re: v2.9.3 and v2.10.0: `name-ref' HEAD gives wrong branch name

From
Jakub Narębski <jnareb@gmail.com>
Date
Sep 21, 2016, 13:43 UTC
Message-ID
<b1d35732-4b4c-e0c1-59da-44d3e3b28799@gmail.com>
In-Reply-To
<CAGyf7-FR11Ludt3vNZX7Ek4n_JLSON5+Y9By83GvNgpg94TWcg@mail.gmail.com>
W dniu 20.09.2016 o 20:54, Bryan Turner pisze:
Show 12 quoted lines
> On Tue, Sep 20, 2016 at 9:23 AM, Steffen Nurpmeso <steffen@sdaoden.eu> wrote:
>> Hello again,
>>
>> yah, sorry, i'm back again..
>> I try to find a way to find the name of the current branch in an
>> automated way, because i need to ensure that a commit happens on
>> it and no other branch.  Now the problem arises that the commit
>> ref at the time of that commit maybe shared in between several
>> different branches, but no more thereafter, of course:
>>
>>   ?0[steffen@wales ]$ git branch|grep '^*'
>>   * stable/v14.9

Not good, 'git branch' is a porcelain (user facing) command, so it output may change; e.g. '*' could be replaced with '•'. For example output for detached HEAD had changed!

Show 15 quoted lines
>>   ?0[steffen@wales ]$ git name-rev --name-only HEAD
>>   stable/v14.8
>>
>> Is there another way except looking into .git/HEAD or using sed(1)
>> on the output of `branch' to find the right name?
> 
> Have you tried "git symbolic-ref HEAD"?
> 
> $ git symbolic-ref HEAD
> refs/heads/master
> 
> If you don't want the fully-qualified ref, you can add --short:
> 
> $ git symbolic-ref --short HEAD
> master

This does not work for detached HEAD, but perhaps you don't need to worry about this.

  $ git rev-parse --symbolic-full-name HEAD
  refs/heads/master
But
  $ git checkout HEAD^0
  Note: checking out 'HEAD^0'.
  You are in 'detached HEAD' state. [...]
 
  $ git rev-parse --symbolic-full-name HEAD
  HEAD
  $ git symbolic-ref HEAD
  fatal: ref HEAD is not a symbolic ref
  $ git branch
  * (HEAD detached at 3e2ebf9)
    master
-- 
Jakub Narębski
Previous: Steffen NurpmesoNext: Steffen Nurpmeso
Message 4 of 7 in “v2.9.3 and v2.10.0: `name-ref' HEAD gives wrong branch name”
  1. Steffen NurpmesoSep 20, 2016
  2. Bryan TurnerSep 20, 2016
  3. Steffen NurpmesoSep 20, 2016
  4. Jakub NarębskiSep 21, 2016
  5. Steffen NurpmesoSep 21, 2016
  6. Junio C HamanoSep 21, 2016
  7. Jakub NarębskiSep 21, 2016

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.