删除的 .git 可以恢复吗? [英] Can deleted .git be restored?

查看:92
本文介绍了删除的 .git 可以恢复吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在 Ruby on Rails 上使用 git 时发生的.完成并创建了多个提交和分支.

This happened when working with git on Ruby on Rails. several commits and branches were done and created.

git version 1.7.3.4

我不小心删除了.git文件夹使用

git -rf .git

但是我在在线 git-hub 存储库上完成了所有文件和更新.我想要恢复 .git 文件夹.问题?

but I have all the files and updates done on online git-hub repository. I want the .git folder restored. Questions ?

  1. 我完全搞砸了吗?或
  2. 如果有办法从我的在线 git-hub 存储库中恢复 .git,如何完成了吗?

推荐答案

恢复已删除的 .git 文件夹的唯一方法是:

The only way you can restore a deleted .git folder is by:

  • 从某处再次克隆它
  • 检查您的回收站或备份(如果不存在远程存储库)

由于您的文件来自在线 github 存储库,因此很简单.只需从删除 .git 文件夹的目录中再次克隆它:

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:

git init
git remote add origin <repo_address>
git pull origin master

其中 repo_address 可以是 git@github.com:yourname/yourproject.git

您的本地结帐将恢复正常.

Your local checkout will be back to normal.

如果您的工作副本中有未提交的更改,您希望保留,而不是使用 git pull 使用 git fetch 然后 git reset --soft 您的本地分支到它应该位于的远程分支.软重置不会改变你的工作副本

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 可以恢复吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆