Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
564 views
in Technique[技术] by (71.8m points)

tortoisegit - Git 'fatal: No such ref: HEAD'

A weird thing happend to my git repository. When I try to commit something in tortoisegit window I receive all files from project. I cannot revert them, when I pull from server I receive fatal: No such ref: HEAD and fatal: Cannot lock the ref 'HEAD'. All my local branches are missing. Is there any way to resolve the problem?

This is not first commit or something. This thing happend suddenly.

EDIT:

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

git status prints all project files marked as new file.

I changed repository folder name for a while, and when I changed it back things were not correct.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You've lost your HEAD so you'll need to recreate it. The simplest thing to do is this.

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

Now you should be able to run other git commands and see where you're at.

(Although, in theory, you could attempt to do git symbolic-ref HEAD refs/heads/master newer git versions don't recognize a .git as a git repository unless it already contains a HEAD so this won't work to create a new one.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...