How can I recover from deleting the .git directory?
I didn't realize all my files were stored and attached to the .git reposi开发者_Python百科tory. I just thought I was deleting .git's version of the proj. I did a
rm -fr .git
I lost all my work! What should I do?
You can check out a new copy of the repository from any remote copy. If you have shared your work with any other developers (i.e. anyone has pull
ed from your repository or you have push
ed into theirs), or if you have your own "master" repository then you should be OK.
You should still have your working copy if the .git directory was the only thing you deleted. All your history will be gone but at least your code won't be.
If this really was the only copy of your work then you may be out of luck, sorry. Unless your filesystem has an "undelete" option (which it probably does not if you're on Linux).
Did you ever push your changes to another repository (i.e. github.com, or somebody else on your team?). Git is distributed, which means things like this should not matter. Just 'git clone' a fresh copy from somewhere that still exists.
If your Git repository was only ever stored in the one place and you'd never pushed it (or originally pulled it) to/from another location, you're out of luck, buddy ;) You still have your working tree, so the best you'll do is to 'git init' and start a new repo from what you currently have.
Sounds like you need to read up on git... that fact that everything lives in the '.git' directory is perhaps one of the most basic aspects to understanding git.
http://www.gitready.com/
精彩评论