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

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

From
UWUlrich Windl <ulrich.windl@rz.uni-regensburg.de>
Date
Apr 2, 2014, 14:52 UTC
Message-ID
<533C404F020000A1000151CE@gwsmtp1.uni-regensburg.de>
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? How does Git find the numeric commit for HEAD? Using find, I found my commit in these files: .git/logs/HEAD .git/logs/refs/heads/shared .git/info/refs .git/packed-refs

Before "git gc" I found the commit ID in HEAD.
Why I'm worrying?: I tried to make a simple script that finds out the current HEAD-commit like this:
            if [ -d .git ]; then
                GIT_HEAD="$(<.git/HEAD)"
                GIT_BRANCH="${GIT_HEAD##*/}"
                GIT_HEAD="Git:$GIT_BRANCH-$(cut -c1-7 .git/${GIT_HEAD##*: })"
            fi
Then $GIT_HEAD was something like "Git:shared-863962c".

Should I use code like this:? awk '$2 == "refs/heads/shared" { print $1 }' .git/info/refs

Of course I'd be most pleased if there was some git builtin to get that (I read the manual without success).
Using an older version of Git (git-1.7.12)...

Regards, Ulrich Windl

Next: Matthieu Moy
Message 1 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.