致命错误:您当前的分支似乎已经损坏。

5
当我使用

时,会出现这个错误。
 git log

致命错误:当前分支已经损坏

我的分支文件已经损坏,我在记事本中打开了.git/refs/heads/mybranch文件,但是我只看到一些乱码。

我知道我必须找到分支的哈希值并将其复制到.git/refs/heads/mybranch文件中,但我不知道如何找到该哈希值。

我阅读了这个主题 [翻译成中文:Git中的损坏分支,致命错误:当前分支已经损坏]


1
我建议尝试使用 git checkout -b new_branch 命令创建一个新分支,然后使用 git branch -D mybranch 命令删除原始分支。接着,你可以将 new_branch 重命名为任何你想要的名称。注意:这假设你当前在与 mybranch 相同的提交上。 - Code-Apprentice
1个回答

16

最终,在经历了很多痛苦之后,这对我起作用了。

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>

第三步应该是“复制倒数第二行”或者“复制倒数第二行”。 - Ganesh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接