简体   繁体   English

删除 .git/HEAD 文件后如何恢复 git 存储库

[英]How to recover git repository after deleting .git/HEAD file

I've got some issues with git and git itself suggested me to delete .git/HEAD if problem persists. git 和 git 本身存在一些问题,如果问题仍然存在,我建议我删除.git/HEAD So I did it and now git says fatal: Not a git repository .所以我做到了,现在 git 说fatal: Not a git repository

I tried running git init on which git responded with reinitializing existing repository but nothing really changed.我尝试运行git init ,git 响应reinitializing existing repository ,但没有真正改变。 I'm unable to run any git command.我无法运行任何 git 命令。

Create new file in .git folder named HEAD and paste there full SHA of some commit.在名为HEAD.git文件夹中创建新文件,并将某些提交的完整 SHA 粘贴到那里。 Then you can run git status to check it current state.然后您可以运行git status来检查它当前的 state。 Now you can simply run git reset and you will end up in latest state before git repository corruption.现在您可以简单地运行git reset ,您将在 git 存储库损坏之前获得最新的 state。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM