使 git 中的克隆存储库成为主存储库
我有两个 git 存储库:
- report.git(远程位置的主控)
- clone.git(本地)
我丢失了report.git。我有克隆的.git。我想从此克隆的.git 克隆其他存储库。这是可能的,但我的问题是我错过了什么吗?克隆的.git 真的和主报告.git 一样吗?
cloned.git 仍然指向主report.git。我通过删除 .git/config 中的选项来更改此设置。这够了吗?
I have two git repositories:
- report.git (Master on remote location)
- cloned.git (Local)
I lost report.git. I have the cloned.git. I want to clone other repositories from this cloned.git. This is possible but my question is am I missing something? Is cloned.git really the same as the master report.git?
cloned.git still points to the Master report.git. I changed this by removing the options in the .git/config. Is this enough?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的cloned.git存储库是report.git的克隆(副本),其状态是您克隆或最后从report.git中提取时的report.git
您的cloned.git一直是master,report.git一直是a大师也。这就是 git 的美妙之处。
Your cloned.git repository is a clone (copy) of report.git in the state that report.git was when you cloned or last pulled from report.git
Your cloned.git has always been a master, report.git has always been a master as well. It's the beauty of git.
http://git-scm.com/docs/git-clone
http://git-scm.com/docs/git-clone
注意:仅当“克隆”存储库是工作存储库(即您提交的非裸存储库,使用单独的存储库)时,才需要下面描述的复杂技术远程布局),而不是裸(或镜像)存储库。如果“cloned.git”是一个裸存储库,则只需执行
git clone --bare
(或git clone --mirror
)即可恢复原始“report.git”存储库(就像 alinrus 写的)。假设您使用默认配置和现代 Git,这意味着“单独的遥控器”布局,您将在“remotes/origin”(或“remotes/report”)命名空间中拥有“report.git”的远程跟踪分支。
要重新创建“report.git”存储库,您必须从远程跟踪分支推送(或获取)一次到普通分支,恢复普通获取引用规范(至少对于分支:标签始终是镜像的)。因此,一次推送(或获取)的 refspec 将类似于以下内容: refs/remotes/origin/*:refs/heads/* 加上 refs/tags/*:refs/标签/*。
恢复会话示例
我们假设原始“report.git”存储库包含两个分支:“master”和“next”,并且没有标签(标签映射为 1-1,所以无论如何它们不应该成为问题):
让 “cloned/.git”存储库是“report.git”的普通(非裸露和非镜像)克隆:
当然,您的分支的状态以及本地分支的数量可能会因您的情况而异。这只是一个简单的例子。
现在让我们删除,或者更好地重命名(移到一边)原始存储库“report.git”,以测试我们的恢复操作
现在我们恢复“report.git”在“cloned/”中上次获取/拉取操作时的状态.git':
现在您可以比较'report.git'和'report-copy.git'是否相同。如果“report.git”是非裸,它们可能会有所不同,因为推送不会更新工作目录(并且您需要执行
git reset --hard HEAD
或< code>git checkout in 'report.git' 你自己),但它是一个裸存储库,不是吗?HTH(希望有帮助)。
Note: Complicated technique desceibed below is required only if 'cloned' repository is working repository (i.e. non-bare repository you commit in, using separate remotes layout), and not bare (or mirror) repository. If 'cloned.git' is a bare repository it is enough to do
git clone --bare
(orgit clone --mirror
) to recover original 'report.git' repository (just like e.g. alinrus wrote).Assuming that you used default configuration and modern Git, which means "separate remotes" layout, you would have remote-tracking branches of 'report.git' in 'remotes/origin' (or 'remotes/report') namespace.
To re-create 'report.git' repository you would have to push (or fetch) once from remote-tracking branches to ordinary branches, reverting ordinary fetch refspec (at least for branches: tags are always mirrored). So the refspec for one time push (or fetch) would be something like the following:
refs/remotes/origin/*:refs/heads/*
plusrefs/tags/*:refs/tags/*
.Example recovery session
Let's assume that original 'report.git' repository contains two branches: 'master' and 'next', and no tags (tags are mapped 1-1, so they shouldn't be a problem, anyway):
Let's have 'cloned/.git' repository to be oridinary (non-bare and non-mirror) clone of 'report.git':
Of course status of your branches, and the number of your local branches might differ for your situation. This is just a simple example.
Now let's remove, or better yet rename (move aside) the original repository 'report.git', to test our recovery operation
Now we recovet the state of 'report.git' that it had on last fetch / pull operation in 'cloned/.git':
Now you can compare 'report.git' and 'report-copy.git' if there are identical. If 'report.git' was non-bare they might differ, because push would not update working directory (and you would need to do
git reset --hard HEAD
orgit checkout
in 'report.git' yourself), but it is a bare repository, isn't it?HTH (hope that helps).