简体   繁体   English

从.git恢复本地git存储库

[英]Recovering local git repository from .git

I have a local git repository that is not pushed onto any git repository hosting sites. 我有一个本地git存储库,该存储库未推送到任何git存储库托管站点上。 I have several commits on this repository. 我在此存储库上有几次提交。

Today, when running git status , I get the error fatal: Not a git repository (or any of the parent directories): .git 今天,当运行git status ,出现fatal: Not a git repository (or any of the parent directories): .git错误fatal: Not a git repository (or any of the parent directories): .git

Running ls -a , I can still see the .git repository and examining the .git/logs/HEAD file, I can also see all of my previous commits. 运行ls -a ,我仍然可以看到.git存储库并检查.git / logs / HEAD文件,还可以看到所有以前的提交。

I would like to recover git in this repository so that I can still revert back to previous commits. 我想在此存储库中恢复git,以便仍然可以恢复到以前的提交。

I'd still like to be able to go back to old commits but so far, it doesn't seem to be able to recognize that there are older commits 我仍然希望能够返回到较早的提交,但到目前为止,它似乎仍无法识别出较旧的提交

If git reflog is not showing you anything... you would need to add, commit and push without being able to get your old history back, unfortunately. 如果git reflog没有显示任何内容,那么很不幸,您需要添加,提交和推送,而又无法恢复您的旧历史记录。

But if git reflog shows you old commits, you can reset your master branch to the most recent one. 但是,如果git reflog显示您的旧提交,则可以将master分支重置为最新的分支。

Make sure you are not running your command from the .git folder itself, but from the parent folder of .git . 确保您不是从.git文件夹本身运行命令,而是从.git的父文件夹运行命令。

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

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