使 git 中的克隆存储库成为主存储库

发布于 2024-08-10 14:18:35 字数 254 浏览 8 评论 0原文

我有两个 git 存储库:

  1. report.git(远程位置的主控)
  2. clone.git(本地)

我丢失了report.git。我有克隆的.git。我想从此克隆的.git 克隆其他存储库。这是可能的,但我的问题是我错过了什么吗?克隆的.git 真的和主报告.git 一样吗?

cloned.git 仍然指向主report.git。我通过删除 .git/config 中的选项来更改此设置。这够了吗?

I have two git repositories:

  1. report.git (Master on remote location)
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

栖迟 2024-08-17 14:18:35

您的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.

帅气尐潴 2024-08-17 14:18:35
git clone --bare localrepo.git newremoterepo.git

http://git-scm.com/docs/git-clone

git clone --bare localrepo.git newremoterepo.git

http://git-scm.com/docs/git-clone

凉城已无爱 2024-08-17 14:18:35

注意:仅当“克隆”存储库是工作存储库(即您提交的非裸存储库,使用单独的存储库)时,才需要下面描述的复杂技术远程布局),而不是裸(或镜像)存储库。如果“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,所以无论如何它们不应该成为问题):

$ git init --bare report.git
# ...
[report.git] $ git branch -a
* master
   next

让 “cloned/.git”存储库是“report.git”的普通(非裸露和非镜像)克隆:

$ git clone [email protected]:report.git cloned
Initialized empty Git repository in /tmp/jnareb/cloned/.git/
# ...
[cloned] $ git branch -a
* master
   remotes/origin/HEAD -> origin/master
   remotes/origin/master
   remotes/origin/next
[cloned] $ git remote show origin
* remote origin
  Fetch URL: [email protected]:report.git
  Push  URL: [email protected]:report.git
  HEAD branch: master
  Remote branches:
    master tracked
    next    tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

当然,您的分支的状态以及本地分支的数量可能会因您的情况而异。这只是一个简单的例子。

现在让我们删除,或者更好地重命名(移到一边)原始存储库“report.git”,以测试我们的恢复操作

$ mv report.git report-copy.git

现在我们恢复“report.git”在“cloned/”中上次获取/拉取操作时的状态.git':

$ git init report.git    # push won't create new repository
# move to 'cloned' repository
[cloned] $ git push [email protected]:report.git 'refs/remotes/origin/*:refs/heads/*'
Counting objects: 12, done.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (12/12), 839 bytes, done.
Total 12 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (12/12), done.
warning: updating the current branch
# long warning about pushing into current branch
To [email protected]:report.git
 * [new branch]      origin/HEAD -> HEAD
 * [new branch]      origin/master -> master
 * [new branch]      origin/next -> next

现在您可以比较'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 (or git 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/* plus refs/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):

$ git init --bare report.git
# ...
[report.git] $ git branch -a
* master
   next

Let's have 'cloned/.git' repository to be oridinary (non-bare and non-mirror) clone of 'report.git':

$ git clone [email protected]:report.git cloned
Initialized empty Git repository in /tmp/jnareb/cloned/.git/
# ...
[cloned] $ git branch -a
* master
   remotes/origin/HEAD -> origin/master
   remotes/origin/master
   remotes/origin/next
[cloned] $ git remote show origin
* remote origin
  Fetch URL: [email protected]:report.git
  Push  URL: [email protected]:report.git
  HEAD branch: master
  Remote branches:
    master tracked
    next    tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

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

$ mv report.git report-copy.git

Now we recovet the state of 'report.git' that it had on last fetch / pull operation in 'cloned/.git':

$ git init report.git    # push won't create new repository
# move to 'cloned' repository
[cloned] $ git push [email protected]:report.git 'refs/remotes/origin/*:refs/heads/*'
Counting objects: 12, done.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (12/12), 839 bytes, done.
Total 12 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (12/12), done.
warning: updating the current branch
# long warning about pushing into current branch
To [email protected]:report.git
 * [new branch]      origin/HEAD -> HEAD
 * [new branch]      origin/master -> master
 * [new branch]      origin/next -> next

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 or git checkout in 'report.git' yourself), but it is a bare repository, isn't it?

HTH (hope that helps).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文