简体   繁体   中英

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. So I create a local repo ( git init ). I had a .gitignore in remote repo so I couldn't push my local files to remote. So I did git checkout origin/master , and all my local files are gone.

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. You may switch to that branch to verify this:

git checkout master

I don't know why you thought to checkout 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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