删除的 .git 可以恢复吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6246907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can deleted .git be restored?
提问by bicepjai
This happened when working with git on Ruby on Rails. several commits and branches were done and created.
在 Ruby on Rails 上使用 git 时会发生这种情况。完成并创建了几个提交和分支。
git version 1.7.3.4
I accidentally deleted the .git folderusing
我不小心删除了.git 文件夹使用
git -rf .git
but I have all the files and updates done on online git-hub repository. I want the .git folder restored. Questions ?
但是我在在线 git-hub 存储库上完成了所有文件和更新。我想要恢复 .git 文件夹。问题 ?
- Am I totally screwed up ? OR
- If theres a way to restore .git from my online git-hub repository, how can that be done ?
- 我完全搞砸了吗?或者
- 如果有办法从我的在线 git-hub 存储库中恢复 .git,那该怎么做?
回答by Mohamed Mansour
The only way you can restore a deleted .git
folder is by:
恢复已删除.git
文件夹的唯一方法是:
- Cloning it again from somewhere
- Checking your recycling bin or backup (if no remote repository exists)
- 从某个地方再次克隆它
- 检查您的回收站或备份(如果不存在远程存储库)
Since your files are from the online github repository, then its simple. Just clone it again from the directory where you deleted the .git
folder:
由于您的文件来自在线 github 存储库,因此很简单。只需从删除.git
文件夹的目录中再次克隆它:
git init
git remote add origin <repo_address>
git pull origin master
where repo_address
can be [email protected]:yourname/yourproject.git
哪里repo_address
可以是[email protected]:yourname/yourproject.git
Your local checkout will be back to normal.
您的本地结帐将恢复正常。
If you have uncommitted changes in your working copy you would want to keep, instead of using git pull
use git fetch
and then git reset --soft
your local branch to the remote branch it should be at. The soft reset will not change your working copy
如果您的工作副本中有未提交的更改,您希望保留,而不是使用git pull
usegit fetch
然后git reset --soft
将本地分支连接到它应该位于的远程分支。软重置不会改变你的工作副本
回答by mimipofi
You can clone your repository to another location and simply copy the cloned .git
folder to the place of your deleted .git
folder.
您可以将存储库克隆到另一个位置,只需将克隆的.git
文件夹复制到已删除.git
文件夹的位置即可。
回答by Shreyansh Panchal
I think the best bet is to Clone the repo in a throwaway folder. And copy the .git folder from that to your desired folder location (The project folder in which you've deleted .git folder).
我认为最好的办法是将 repo 克隆到一个一次性文件夹中。并将 .git 文件夹从中复制到所需的文件夹位置(已删除 .git 文件夹的项目文件夹)。
回答by Christa King
if you compiled your work and it is in a jar format. Go to your .m2/repository/location and find that jar file. change the .jar to .zip. unzip the file and your git repository should be there.
如果您编译了您的作品并且它是 jar 格式。转到您的 .m2/repository/location 并找到该 jar 文件。将 .jar 更改为 .zip。解压缩文件,您的 git 存储库应该在那里。