还原.git文件夹的最佳方法 [英] Best way to restore .git folder

查看:288
本文介绍了还原.git文件夹的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于代码中的某些错误,我们丢失了完整的GIT控制目录.恢复文件不是问题. TimeMachine照顾了这一点.但是,TimeMachine显然没有备份.git文件夹.

Due to some error in code, we lost a complete GIT-controlled directory. Restoring the files was not a problem; TimeMachine took care of that. However, TimeMachine apparently did not back up the .git folder.

是否有比从主服务器或另一台计算机上获取目录更好的方法来还原/重新创建.git文件夹?

Is there a better way to restore/recreate the .git folder than to fetch the directory from the master server or another machine?

在此先感谢您提供任何有用的提示.

Thanks in advance for any useful hint.

推荐答案

您可以签出裸露的.git存储库,然后通过添加源代码将其扩展为完整的存储库.这仍然会下载整个.git文件夹,而不是您的工作副本代码文件.

You can check out a bare .git repo and then inflate it into a full repo by adding your source code. This will still download the entire .git folder but not your working copy code files.

  1. 创建一个新文件夹并导航到它.
  2. 克隆裸仓库:

  1. Create a new folder and navigate to it.
  2. Clone a bare repo:

git clone --bare https://path/to/project .git

将您本地恢复的文件复制到.git文件夹(与之前的相对位置相同)中.

Copy your locally recovered files around the .git folder (in the same relative location as they were earlier).

将新的仓库标记为非裸仓库:

Mark the new repo as non-bare:

git config --local --bool core.bare false

最后重置索引:

git reset HEAD -- .

这篇关于还原.git文件夹的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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