5

I give this error when I use

 git log

fatal: your current branch appears to be broken

my branch file was broked I opened .git/refs/heads/mybranch in notepad but I see only some ????????? in file

I know I must find branch hash and copy that into .git/refs/heads/mybranch file but I don't how to find that hash

I read this topic Broken branch in git, fatal: your current branch appears to be broken

yas17
  • 401
  • 1
  • 3
  • 14
  • 1
    I suggest trying `git checkout -b new_branch` to create a new branch and then `git branch -D mybranch` to delete your original branch. Then you can rename `new_branch` to whatever you want. Note: this assumes you are currently on the same commit as `mybranch`. – Code-Apprentice Aug 20 '19 at 20:31

1 Answers1

16

finally, after very pain, this worked for me

1 get backup from your .git directory
2 open file .git\logs\refs\heads\<branch name> with your editor 
3 copy second hash of your last line
4 open file .git\refs\heads\<branch name> and delete everything in this file
5 past that hash to .git\refs\heads\<branch name>
yas17
  • 401
  • 1
  • 3
  • 14
  • The 3rd step should be `Copy the last but one line` or `Copy the second line from the last` – Ganesh Apr 28 '23 at 09:08