{"thread":{"id":"36338","subject":"Re: Q: \".git/HEAD\" and \".git/refs/heads\"","startedAt":"2014-04-02T14:52:31Z","lastAt":"2014-04-03T08:04:48Z","messageCount":3,"participants":["Matthieu Moy","Ulrich Windl"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"238311","messageId":"533C404F020000A1000151CE@gwsmtp1.uni-regensburg.de","threadId":"36338","inReplyTo":null,"subject":"Q: \".git/HEAD\" and \".git/refs/heads\"","fromName":"Ulrich Windl","fromEmail":"ulrich.windl@rz.uni-regensburg.de","sentAt":"2014-04-02T14:52:31Z","receivedAt":"2014-04-02T14:52:31Z","isPatch":false,"sender":{"key":"ulrich.windl@rz.uni-regensburg.de","avatar":null},"body":"Hi!\n\nI have a small question: After a \"git gc\" with last commit being \"[shared 2679648]\" I found this:\n> cat .git/HEAD\nref: refs/heads/shared\n> cat .git/refs/heads/shared\ncat: .git/refs/heads/shared: No such file or directory\n\nIs this intentional? How does Git find the numeric commit for HEAD?\nUsing find, I found my commit in these files:\n.git/logs/HEAD\n.git/logs/refs/heads/shared\n.git/info/refs\n.git/packed-refs\n\nBefore \"git gc\" I found the commit ID in HEAD.\n\nWhy I'm worrying?: I tried to make a simple script that finds out the current HEAD-commit like this:\n            if [ -d .git ]; then\n                GIT_HEAD=\"$(<.git/HEAD)\"\n                GIT_BRANCH=\"${GIT_HEAD##*/}\"\n                GIT_HEAD=\"Git:$GIT_BRANCH-$(cut -c1-7 .git/${GIT_HEAD##*: })\"\n            fi\n\nThen $GIT_HEAD was something like \"Git:shared-863962c\".\n\nShould I use code like this:?\nawk '$2 == \"refs/heads/shared\" { print $1 }' .git/info/refs\n\nOf course I'd be most pleased if there was some git builtin to get that (I read the manual without success).\n\nUsing an older version of Git (git-1.7.12)...\n\nRegards,\nUlrich Windl\n"},{"id":"238292","messageId":"vpqob0jwrbb.fsf@anie.imag.fr","threadId":"36338","inReplyTo":"533C404F020000A1000151CE@gwsmtp1.uni-regensburg.de","subject":"Re: Q: \".git/HEAD\" and \".git/refs/heads\"","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2014-04-02T17:54:00Z","receivedAt":"2014-04-02T17:54:00Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"\"Ulrich Windl\" <Ulrich.Windl@rz.uni-regensburg.de> writes:\n\n> Hi!\n>\n> I have a small question: After a \"git gc\" with last commit being \"[shared 2679648]\" I found this:\n>> cat .git/HEAD\n> ref: refs/heads/shared\n>> cat .git/refs/heads/shared\n> cat: .git/refs/heads/shared: No such file or directory\n>\n> Is this intentional?\n\nYes.\n\n> commit in these files: .git/logs/HEAD .git/logs/refs/heads/shared\n> .git/info/refs .git/packed-refs\n\nYes, they are where the refs are stored. If you have many refs in your\nrepository, having one file per ref is inefficient. It's more efficient\nfor Git to have one big read-only file. When one ref is modified, the\n.git/refs/heads/$branch file is re-created, and the packed entry is\nignored.\n\n>             if [ -d .git ]; then\n>                 GIT_HEAD=\"$(<.git/HEAD)\"\n>                 GIT_BRANCH=\"${GIT_HEAD##*/}\"\n>                 GIT_HEAD=\"Git:$GIT_BRANCH-$(cut -c1-7 .git/${GIT_HEAD##*: })\"\n>             fi\n\nDon't access the filesystem. Ask Git.\n\nGIT_FULL_BRANCH=$(git rev-parse --symbolic-full-name HEAD)\nGIT_BRANCH=\"${GIT_FULL_BRANCH##*/}\"\nGIT_HEAD=\"Git:$GIT_BRANCH-$(git rev-parse --short HEAD)\"\n\n(Perhaps there's a simpler way without $GIT_FULL_BRANCH)\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"238343","messageId":"533D3240020000A1000151F5@gwsmtp1.uni-regensburg.de","threadId":"36338","inReplyTo":"vpqob0jwrbb.fsf@anie.imag.fr","subject":"Antw: Re: Q: \".git/HEAD\" and \".git/refs/heads\"","fromName":"Ulrich Windl","fromEmail":"ulrich.windl@rz.uni-regensburg.de","sentAt":"2014-04-03T08:04:48Z","receivedAt":"2014-04-03T08:04:48Z","isPatch":false,"sender":{"key":"ulrich.windl@rz.uni-regensburg.de","avatar":null},"body":">>> Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> schrieb am 02.04.2014 um 19:54 in\nNachricht <vpqob0jwrbb.fsf@anie.imag.fr>:\n> \"Ulrich Windl\" <Ulrich.Windl@rz.uni-regensburg.de> writes:\n> \n>> Hi!\n>>\n>> I have a small question: After a \"git gc\" with last commit being \"[shared \n> 2679648]\" I found this:\n>>> cat .git/HEAD\n>> ref: refs/heads/shared\n>>> cat .git/refs/heads/shared\n>> cat: .git/refs/heads/shared: No such file or directory\n>>\n>> Is this intentional?\n> \n> Yes.\n> \n>> commit in these files: .git/logs/HEAD .git/logs/refs/heads/shared\n>> .git/info/refs .git/packed-refs\n> \n> Yes, they are where the refs are stored. If you have many refs in your\n> repository, having one file per ref is inefficient. It's more efficient\n> for Git to have one big read-only file. When one ref is modified, the\n> .git/refs/heads/$branch file is re-created, and the packed entry is\n> ignored.\n> \n>>             if [ -d .git ]; then\n>>                 GIT_HEAD=\"$(<.git/HEAD)\"\n>>                 GIT_BRANCH=\"${GIT_HEAD##*/}\"\n>>                 GIT_HEAD=\"Git:$GIT_BRANCH-$(cut -c1-7 .git/${GIT_HEAD##*: })\"\n>>             fi\n> \n> Don't access the filesystem. Ask Git.\n> \n> GIT_FULL_BRANCH=$(git rev-parse --symbolic-full-name HEAD)\n> GIT_BRANCH=\"${GIT_FULL_BRANCH##*/}\"\n> GIT_HEAD=\"Git:$GIT_BRANCH-$(git rev-parse --short HEAD)\"\n> \n> (Perhaps there's a simpler way without $GIT_FULL_BRANCH)\n\nMatthieu,\n\nthanks for this (it not so abvious how to use \"git --rev-parse\")!\n\nUlrich\n"}]}