简体   繁体   English

如何恢复使用命令(Git checkout…)删除的所有已删除本地文件?

[英]How to recover all deleted local files which were deleted using command (Git checkout …)?

I had a project which I wanted to push to Git. 我有一个项目想要推广到Git。 So I create a local repo ( git init ). 所以我创建了一个本地仓库( git init )。 I had a .gitignore in remote repo so I couldn't push my local files to remote. 我在远程存储库中有一个.gitignore ,因此无法将本地文件推送到远程。 So I did git checkout origin/master , and all my local files are gone. 所以我做了git checkout origin/master ,所有本地文件都消失了。

Is there any way to recover them? 有什么办法可以恢复它们?

Here's what I have done: 这是我所做的:

git init
git add .
git commit -m "Initial commit"
git push origin master (failed)
git checkout origin/master

Assuming your git commit -m "Initial commit" step actually completed successfully, then your local master should have all your work. 假设您的git commit -m "Initial commit"步骤实际上已成功完成,那么您的本地master应具有所有工作。 You may switch to that branch to verify this: 您可以切换到该分支以验证这一点:

git checkout master

I don't know why you thought to checkout origin/master . 我不知道您为什么要签出origin/master This is the remote tracking branch, and it doesn't really have anything to do with your current problem. 这是远程跟踪分支,实际上与您当前的问题没有任何关系。 You need to resolve the reason why your pushes are being rejected. 您需要解决推送被拒绝的原因。

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

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