git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Q: ".git/HEAD" and ".git/refs/heads"
@ 2014-04-02 14:52 Ulrich Windl
  2014-04-02 17:54 ` Matthieu Moy
  0 siblings, 1 reply; 3+ messages in thread
From: Ulrich Windl @ 2014-04-02 14:52 UTC (permalink / raw
  To: git

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Q: ".git/HEAD" and ".git/refs/heads"
  2014-04-02 14:52 Q: ".git/HEAD" and ".git/refs/heads" Ulrich Windl
@ 2014-04-02 17:54 ` Matthieu Moy
  2014-04-03  8:04   ` Antw: " Ulrich Windl
  0 siblings, 1 reply; 3+ messages in thread
From: Matthieu Moy @ 2014-04-02 17:54 UTC (permalink / raw
  To: Ulrich Windl; +Cc: git

"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 Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Antw: Re: Q: ".git/HEAD" and ".git/refs/heads"
  2014-04-02 17:54 ` Matthieu Moy
@ 2014-04-03  8:04   ` Ulrich Windl
  0 siblings, 0 replies; 3+ messages in thread
From: Ulrich Windl @ 2014-04-03  8:04 UTC (permalink / raw
  To: Matthieu Moy; +Cc: git

>>> Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> schrieb am 02.04.2014 um 19:54 in
Nachricht <vpqob0jwrbb.fsf@anie.imag.fr>:
> "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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-04-03 10:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-02 14:52 Q: ".git/HEAD" and ".git/refs/heads" Ulrich Windl
2014-04-02 17:54 ` Matthieu Moy
2014-04-03  8:04   ` Antw: " Ulrich Windl

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).