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

Antw: Re: Q: ".git/HEAD" and ".git/refs/heads"

From
UWUlrich Windl <ulrich.windl@rz.uni-regensburg.de>
Date
Apr 3, 2014, 08:04 UTC
Message-ID
<533D3240020000A1000151F5@gwsmtp1.uni-regensburg.de>
In-Reply-To
<vpqob0jwrbb.fsf@anie.imag.fr>
>>> Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> schrieb am 02.04.2014 um 19:54 in
Nachricht <vpqob0jwrbb.fsf@anie.imag.fr>:
Show 37 quoted lines
> "Ulrich Windl" <Ulrich.Windl@rz.uni-regensburg.de> writes:
> 
>> Hi!
>>
>> I have a small question: After a "git gc" with last commit being "[shared 
> 2679648]" I found this:
>>> cat .git/HEAD
>> ref: refs/heads/shared
>>> cat .git/refs/heads/shared
>> cat: .git/refs/heads/shared: No such file or directory
>>
>> Is this intentional?
> 
> Yes.
> 
>> commit in these files: .git/logs/HEAD .git/logs/refs/heads/shared
>> .git/info/refs .git/packed-refs
> 
> Yes, they are where the refs are stored. If you have many refs in your
> repository, having one file per ref is inefficient. It's more efficient
> for Git to have one big read-only file. When one ref is modified, the
> .git/refs/heads/$branch file is re-created, and the packed entry is
> ignored.
> 
>>             if [ -d .git ]; then
>>                 GIT_HEAD="$(<.git/HEAD)"
>>                 GIT_BRANCH="${GIT_HEAD##*/}"
>>                 GIT_HEAD="Git:$GIT_BRANCH-$(cut -c1-7 .git/${GIT_HEAD##*: })"
>>             fi
> 
> Don't access the filesystem. Ask Git.
> 
> GIT_FULL_BRANCH=$(git rev-parse --symbolic-full-name HEAD)
> GIT_BRANCH="${GIT_FULL_BRANCH##*/}"
> GIT_HEAD="Git:$GIT_BRANCH-$(git rev-parse --short HEAD)"
> 
> (Perhaps there's a simpler way without $GIT_FULL_BRANCH)
Matthieu,
thanks for this (it not so abvious how to use "git --rev-parse")!
Ulrich
Previous: Matthieu Moy
Message 3 of 3 in “Q: ".git/HEAD" and ".git/refs/heads"”
  1. Ulrich WindlApr 2, 2014
  2. Matthieu MoyApr 2, 2014
  3. Antw: Re: Q: ".git/HEAD" and ".git/refs/heads"Ulrich Windl, Apr 3, 2014

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.