I am getting fatal: Failed to resolve HEAD as a valid ref. whenever I try to commit.
I have tried
echo ref: refs/heads/master >.git/HEAD
but its not working
Also tried
git commit
its not working either from below sources
Git 'fatal: No such ref: HEAD' git tag: fatal: Failed to resolve 'HEAD' as a valid ref
Please help in..All my commit history is also gone
I have also encountered the same issue, and have resolved it as follows:
.git
folder of the cloned project..git
folder of the original project with the one that you've have copied.Why does this happen?
.git
folder and if they are corrupted git can no longer recognize the repository.Caveats
Everything in your previous .git
folder will be gone. Configurations like remote reference name(s) must be set up again.
I got this issue due a disk failure. I know this is an old question but maybe it can help someone. In my case I had a local branch where I was working on before my repo got corrupted so re-cloning the repo was not suitable for me. Any answer here or in other post helped me, except this little piece of code I found here. I just ran this command in the root of my repo:
echo ref: refs/heads/master >.git/HEAD
After that, I was able to excecute, git branch
, git commit
and all other git commands.
I hope this can help someone!
My problem was with
git init
git add .
Tried
git reset
fatal: Failed to resolve 'HEAD' as a valid ref.
git reset --hard
fatal: Failed to resolve 'HEAD' as a valid ref.
Solved with
git rm -r --cached .
Enviroment
git version 1.7.5.4
Ubuntu 11.10
In my case, I ended up with two branches with the same name after a branch renaming. By removing one of them in .git/refs/heads it all went back to normal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With