Git 'fatal: No such links: HEAD'

A strange thing happened in my git repository. When I try to commit something to the tortoisegit window, I get all the files from the project. I can’t get them back when I pull it from the server, I get fatal: No such ref: HEAD and fatal: Cannot lock the ref 'HEAD' . All my local branches are missing. Is there any way to solve the problem?

This is not the first commit or anything else. It unexpectedly happened.

EDIT:

git branch -a says: Failed to resolve HEAD as a valid ref

git status prints all project files marked as a new file.

I changed the name of the repository folder for a while, and when I changed it, everything was wrong.

+44
git tortoisegit
Jan 31 '11 at 7:39
source share
4 answers

You have lost HEAD , so you need to recreate it. The simplest thing is this.

 echo ref: refs/heads/master >.git/HEAD 

Now you can run other git commands and see where you are.

(Although theoretically you can try to make git symbolic-ref HEAD refs/heads/master versions of git symbolic-ref HEAD refs/heads/master newer git will not recognize .git as a git repository if it already contains HEAD , so this will not work to create a new one.)

+66
Jan 31 '11 at 8:29
source share
β€” -

HEAD usually a reference to a specific branch; in your case, it seems that the branch pointers are gone, so the HEAD link cannot be resolved.

You can use git fsck --lost-found to scan the object cache for inaccessible objects; in particular, you are interested in commits, which can then be found below .git/lost-found/commit/ ; these are pointers to your branches, all you have to do is figure out what it is and create new links using git branch .

+6
Jan 31 2018-11-11T00:
source share

I think this answer might be useful for someone. I almost solved this problem. At first I did, as Charles Bailey wrote, use

 echo ref: refs/heads/master >.git/HEAD 

Then my branch changed to master. I made changes and was able to switch to my main branch. The problem was that I could not use any of my local branches. I especially wanted to work on branch 812. Therefore, I found the last commit for branch 812 (create a message when commit is very useful;)) and switched to it. Then I created branch 812 based on the one I switched to. Unfortunately, some files were missing. Fortunately, I had them on a broken repo, which I copied before the "echo"

+6
Jan 31 '11 at 9:29
source share

For me, the problem was that on Mac OS X the 'uchg' or 'uappnd' flag was set, blocking some git files regardless of perms. I reset chflags like this and he solved this for me:

 sudo chflags -R 0000 . 
+2
Apr 24 '12 at 3:15
source share



All Articles