git status shows fatal: bad object HEAD

前端 未结 14 1261
醉酒成梦
醉酒成梦 2020-12-09 00:44

I have a problem with git on Windows Azure. Git status shows - \"fatal: bad object HEAD\" and I tried running:

 git fsck --full
 git gc

But

相关标签:
14条回答
  • 2020-12-09 00:58

    I managed to fix a similar problem to this when some of git's files were corrupted:

    https://stackoverflow.com/a/30871926/1737957

    In my answer on that question, look for the part where I had the same error message as here:

    fatal: bad object HEAD.
    

    You could try following what I did from that point on. Make sure to back up the whole folder first.

    Of course, your repository might be corrupted in a completely different way, and what I did won't solve your problem. But it might give you some ideas! Git internals seem like magic, but it's really just a bunch of files which can be edited, moved, deleted the same as any others. Once you have a good idea of what they do and how they fit together you have a good chance of success.

    0 讨论(0)
  • 2020-12-09 00:59

    This happened because by mistake I removed some core file of GIT. Try this its worked for me.

    re-initialize git

    git init
    

    fetch data from remote

    git fetch
    

    Now check all your changes and git status by

    git status
    
    0 讨论(0)
  • 2020-12-09 00:59

    I solved this by doing git fetch. My error was because I moved my file from my main storage to my secondary storage on windows 10.

    0 讨论(0)
  • 2020-12-09 01:02

    This is unlikely to be the source of your problem - but if you happen to be working in .NET you'll end up with a bunch of obj/ folders. Sometimes it is helpful to delete all of these obj/ folders in order to resolve a pesky build issue.

    I received the same fatal: bad object HEAD on my current branch (master) and was unable to run git status or to checkout any other branch (I always got an error refs/remote/[branch] does not point to a valid object).

    If you want to delete all of your obj folders, don't get lazy and allow .git/objects into the mix. That folder is where all of the actual contents of your git commits go.

    After being close to giving up I decided to look at which files were in my recycle bin, and there it was. Restored the file and my local repository was like new.

    0 讨论(0)
  • 2020-12-09 01:05

    Your repository is broken. But you can probably fix it AND keep your edits:

    1. Back up first: cp your_repository your_repositry_bak
    2. Clone the broken repository (still works): git clone your_repository your_repository_clone
    3. Replace the broken .git folder with the one from the clone: rm -rf your_repository/.git && cp your_repository_clone/.git your_repository/ -r
    4. Delete clone & backup (if everything is fine): rm -r your_repository_*
    0 讨论(0)
  • 2020-12-09 01:05

    I solved this by renaming the branch in the file .git/refs/remotes/origin/HEAD.

    0 讨论(0)
提交回复
热议问题