git - 克隆一个镜像的本地 Git 存储库
问题描述
我已经镜像 ( clone --mirror
) 一个没有远程引用的本地存储库,仅用于备份目的。我注意到备份的 repo 有一个带有本地refs 的“packed-refs”文件。
当我尝试将其克隆回来时,我得到了相同的“打包引用”文件,其中包含远程引用,例如remotes/origin/heads/...而不是本地引用。然后,我必须检查每个 refs 以获得本地 refs。
有没有办法,也许是一些clone
选项,能够直接恢复本地参考?
解决方案
如果您从某个现有克隆中创建了一个裸克隆,并且现有克隆已被销毁(或者您可能正在新的服务器设置上重新创建它),您有两种选择:
- 将新的裸克隆创建为空克隆,然后使用
git push --mirror
从备份/镜像克隆到新克隆,或者 - 从现有的裸克隆中使用
git clone --mirror
来创建一个新的裸克隆,然后可以选择删除在新的裸克隆中创建的远程。
例如,假设ec$
这里的提示是在现有的镜像克隆上ec.example.com
,并且ns$
是新服务器上的提示,ns.example.com
:
ns$ cd /git && mkdir restored && cd restored && git init --bare
[git messages happen here]
ec$ git push --mirror ssh://ns.example.com/git/restored
在git push --mirror
中设置新服务器的克隆/git/restored
。
或者:
ns$ cd /git
ns$ git clone --mirror ssh://ec.example.com/~user/backup/the-mirror restored
[git messages happen here]
ns$ cd restored
ns$ git remote remove origin
该git remote remove
步骤是可选的;它清理了表明恢复的裸镜像克隆来自的痕迹ec.example.com/~user/backup/the-mirror
。由于这些跟踪仅对首先实际登录到服务器的任何人可见,因此这并不是真正需要的,但您可能出于自己的任何原因喜欢它。
推荐阅读
- django - 提交表单后将用户重定向到特定提交
- javascript - 我应该如何将数据传递到通过 USB 连接的设备以与套接字发生反应?
- json - 解析 AWS CLI 命令
- reactjs - 反应过渡组:切换可以变为空的元素
- css - 使用 Google 字体 CSS 规则,但仍然“无法解码下载的字体”?
- python - 做
.all() 在 Python 中使用 Cassandra 时在使用时擦除数据? - python - 从图像消息转换回 cv2 图像仅显示白屏:“bridge.imgmsg_to_cv2”
- angular - 隐藏 PrimeNG Autocomplete Multiple 上的选定值
- python-3.x - 如何在 python 中将 pandas DataFrame 转换为 YAML
- javascript - spec.type 必须在 react-dnd 中定义