git 从二级远程获取

发布于 2024-10-06 06:00:30 字数 447 浏览 1 评论 0原文

我的远程存储库(称为 repoSlow)的网络链接非常慢,我偶尔会从该存储库获取主开发存储库(称为 repo1)。

有时我将 repo1 克隆到另一个目录中的 repo2 来进行测试,例如在其他分支上进行测试,而不会丢失 repo1 的状态(也涉及对象文件和库,因此简单的存储无法做到这一点)。

为了将 repoSlow 的状态获取到 repo2,我通常必须存储在 repo1 中,签出并合并从 repoSlow 到 repo1 的每个分支(我感兴趣),然后将它们获取到 repo2。

除了程序繁琐和其他一些问题之外,我有时不想合并到 repo1 中。签出不同的本地分支名称将导致命名混乱。

有没有一种简单直接的方法来实际获取遥控器的遥控器?

我想更好的工作流程可能是将 repoSlow 克隆到一个裸露的(甚至是镜像的?)本地存储库并多次克隆该存储库,但为了更好地理解 git,我保留了原来的问题。

I have a very slow network link to my remote repository (call it repoSlow) from which I fetch once in a while to my main development repo (call it repo1).

Sometimes I clone repo1 to repo2 in another directory to do tests e.g. on other branches without losing the state of repo1 (also concerning object files and libraries, therefore a simple stash won't do it).

In order to get the state of repoSlow into repo2 I have usually to stash in repo1, checkout and merge every branch (I am interested in) from repoSlow to repo1, then fetch them to repo2.

Besides the fact that it is a cumbersome procedure and some other points, I sometimes don't want to merge in repo1. Checking out to a different local branch name will result in a big naming mess.

Is there an easy and direct way to in fact fetch the remote of a remote?

I guess that a better workflow might be to clone repoSlow to a bare (or even mirrored?) local repo and clone that one multiple times, but for the sake of better understanding git I maintain the original question.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

落日海湾 2024-10-13 06:00:30

你是对的,最好在本地克隆到一个裸仓库作为集成点,然后从中克隆你的 repo1 和 repo2。

但要回答你原来的问题,我不相信有一种方法可以直接获取遥控器的遥控器;但是您可以在从 repo1 克隆 repoSlow 后将其添加为 repo2 中的遥控器。如果你这样做,它只需要从 repoSlow 获取它没有从 repo1 克隆的东西,这应该比获取完整历史记录要快得多。

为此,只需从 repo2 中运行以下命令:

git remote add upstream git://example.com/path/to/repo/slow.git
git remote update

现在 repo2 中应该有两个遥控器; origin 指的是 repo1,而 upstream (或者任何你想称呼的名称)指向你的 repoSlow。

You are right, it would probably be best to clone to a bare repo locally as your integration point, and then clone your repo1 and repo2 from that.

But to answer your original question, I don't believe that there is a way to directly fetch the remote of a remote; but you could just add repoSlow as a remote in repo2 after cloning it from repo1. If you do that, it will only have to fetch from repoSlow the things that it didn't clone from repo1, which should be considerably faster than fatching the full history.

To do this, just run the following from within repo2:

git remote add upstream git://example.com/path/to/repo/slow.git
git remote update

Now you should have two remotes in repo2; origin referring to repo1, and upstream (or whatever you want to call it) pointing to your repoSlow.

指尖上的星空 2024-10-13 06:00:30

您可以在 repo2 中进行如下配置:

[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        fetch = +refs/remotes/origin/*:refs/remotes/ancestor/*

这告诉 repo2 不仅要获取 repo1 的分支(并将它们镜像为 origin/*),还要获取 repo1 的起源跟踪分支(并将它们镜像为ancestor/*)

所以现在你只需要在 repo1 中执行“git fetch”即可从 repoSlow 获取更改,而无需更改任何本地分支,然后你就可以将这些更改提取到 repo2 中以及。

You can make a configuration like this in repo2:

[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        fetch = +refs/remotes/origin/*:refs/remotes/ancestor/*

This tells repo2 to not only fetch repo1's branches (and mirror them as origin/*) but also to fetch repo1's tracking branches of its origin (and mirror them as ancestor/*)

So now you need only do a "git fetch" in repo1 to fetch changes from repoSlow, without changing any local branches at all, and then you will be able to fetch those changes into repo2 as well.

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