克隆git存储库并保留无法访问的提交 [英] Clone a git repository and keep unreachable commits

查看:72
本文介绍了克隆git存储库并保留无法访问的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种克隆远程git存储库的方法,同时保留该存储库中可能存在的所有无法访问的提交?

Is there a way to clone a remote git repo while keeping any unreachable commits that may be in that repo?

情况是这样的:我需要恢复从维护的服务器上的裸git存储库中删除的分支.我具有对该分支的最后一次提交的哈希,但是常规git命令似乎无法在裸仓库上运行,据我所知,没有任何方法可以直接在服务器上恢复它.

The scenario is this: I need to recover a branch that was deleted from a bare git repo on a server that I maintain. I have the hash of the last commit to this branch, but The regular git commands do not seem to be able to function on bare repos, so as far as I am aware there is not any way I can recover it directly on the server.

我也无权访问包含此提交的任何非裸仓库.如果这样做,我可以通过检出提交哈希值然后从中创建一个分支来轻松地恢复它.这就是为什么我希望能够克隆此存储库,同时保留所有无法访问的提交的原因,因此我可以做到这一点.

I also do not have access to any non-bare repos that contain this commit. If I did, I could recover it easily by checking out the commit hash and then creating a branch from it. This is why I would like to be able to clone this repo while keeping any unreachable commits in it, so I can do exactly that.

推荐答案

您想要做的是:

  1. 使用常规文件复制命令将裸仓库复制到另一个文件夹.
  2. 转化裸仓库副本复制到普通仓库.
  3. 执行所需的操作以找到所需的提交对象.
  4. 在丢失的提交位置找到新分支.
  5. 将原始的裸仓库添加为遥控器.
  6. 将新分支推送到裸仓库.
  1. Copy the bare repo to another folder using normal file copy commands.
  2. Convert the bare repo copy to a normal repo.
  3. Do what you need to do to locate the commit object you seek.
  4. Create a new branch at the lost commit once its located.
  5. Add the original bare repo as a remote.
  6. Push the new branch up to the bare repository.

这篇关于克隆git存储库并保留无法访问的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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