Home > Enterprise >  git recreate refs/heads/master after gc
git recreate refs/heads/master after gc

Time:07-22

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

CodePudding user response:

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.

CodePudding user response:

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.

  • Related