This may be hard to believe, but I was in the middle of executing a commit when my power went off. Luckily, I never pushed the commit. I just got my power back and when I tried to execute git log
in the directory and I got the error:
fatal: bad default revision 'HEAD'
This is a private repository that I had been working on for a little over a week and have made about 5 - 10 commits.
I looked on SO and found Git tracking entire home directory. Get error - fatal: bad default revision 'HEAD', which was not of any help because I have already run a git init
!
I just ran ls -la
to see if my .gitignore
file was still there, but lo and behold it was gone. What should I do? I don't want to lose my previous commits history.
My knowledge of Git is limited. Any help would be appreciated.
Edit 1:
I only have one branch (master) and when I tried: git symbolic-ref HEAD refs/heads/master
it didn't change anything.
I also looked at git log and show on a bare repo and tried:
git log --graph --oneline --date-order --decorate --color --all
which gave me:
095cdaa (origin/master) added profile layout
dd9ddec fixed nav bar
4e99ca7 remove unecessary files, add resources, start navigation drawer
8b09709 fix README
c64c422 initial commit
I then tried git branch master 095cdaa...
, which gave me the error:
fatal: Failed to resolve HEAD as a valid ref.
Edit 2:
As a quick fix to this problem, I did what @PaulGriffiths suggested:
- Clone the repository
- Copy the changed files and commit them
- Run
rm -f ./.git/index.lock