3

After restarting my computer, 'git commit' & 'git status' both return an error message:

error: bad signature

fatal: index file corrupt

running 'git branch':

fatal: Failed to resolve HEAD as a valid ref.

running 'git log':

fatal: your current branch appears to be broken


What causes this? How can I restore/fix my local repo/branch?

Hugo y
  • 1,421
  • 10
  • 20
Don
  • 3,876
  • 10
  • 47
  • 76

1 Answers1

5

I found a solution that worked for me.

  1. Re-clone the repository into another directory.
  2. Copy the .git folder from newly cloned repo & replace the one in the original repo.

This will repair the detached HEAD state which occurred as a result of (in this particular case) uncommitted changes that were discarded (but saved locally) when computer was forced to shut down.

Community
  • 1
  • 1
Don
  • 3,876
  • 10
  • 47
  • 76
  • Where can I find the .git folder from the newly cloned repo? – Sven Brodersen Feb 19 '21 at 15:11
  • 1
    It should be in the root directory of your repository. Depending on your settings and what you are using (file explorer or terminal) it may be hidden. – Don Feb 22 '21 at 20:09