0

after I run git gc --prune=now the file .git/refs/heads/master is deleted

how to recreate it? a remote application needs to read its text content (commit hash)

.git/HEAD content : ref: refs/heads/master

matt
  • 515,959
  • 87
  • 875
  • 1,141
geek175
  • 127
  • 1
  • 7

3 Answers3

1

If the file does not exist, you're not supposed to be using the file: the branch hash ID is now stored somewhere else. Use git rev-parse or git for-each-ref to avoid depending on how the branch's value is stored.

If you have bad software you cannot fix, the trick to getting the branch file re-created is currently to make Git think that branch master has been modified. To do that, make a commit and then un-make it, or use git reset to reset it to where it is; but remember that anything that works today might start failing tomorrow. Someday there won't be any files here, so that case-sensitive branch names work on Windows.

torek
  • 448,244
  • 59
  • 642
  • 775
1

git gc packs refs and objects. Packed refs are stored in .git/packed-refs. There are many internal files under .git. Do not directly read these files. Use git commands instead, like git rev-parse refs/heads/master or git for-each-ref refs/heads/master or git log -1 --pretty=%H refs/heads/master.

ElpieKay
  • 27,194
  • 6
  • 32
  • 53
0

git ls-remote <repo> refs/heads/master is the solution, it works with both local and remote repositories

geek175
  • 127
  • 1
  • 7
  • 1
    `git ls-remote` reads the commit of the master branch in the remote repository. The commit could be different from the master branch in the local repository. – ElpieKay Jul 22 '22 at 06:27
  • @ElpieKay: I think that was the OPs goal (that is, the question was "how do I read the hash ID from a remote repository that happens to be, at the moment, readable via a mounted drive"). – torek Jul 22 '22 at 18:43