克隆 git-from-svn 存储库并获取所有远程分支

发布于 2024-08-27 07:10:03 字数 1051 浏览 8 评论 0原文

我正在努力了解如何能够从 Subversion 克隆 git 存储库,然后将该存储库克隆到另一台计算机(git-to-git),并且仍然可以访问所有原始 Subversion 分支和标签。这是我所做的,以及遇到障碍的地方。

首先,在机器 A 上,我将 Subversion 存储库克隆到 git 存储库中:

[machine A]$ git svn clone -s http://svn.repo.url/MyProject

这给了我一个 git 存储库,其中包含原始 Subversion 存储库的整个历史记录以及所有分支和标签:

[machine A]$ git branch -r
* master
  remotes/v1
  remotes/v1.1
  remotes/v1.2
  remotes/test_migration
  remotes/tags/20100104
  remotes/tags/20100308
  remotes/trunk

现在,在机器 B 上,我想克隆该 git存储库,并且仍然可以访问所有原始 Subversion 分支和标签。首先,我克隆了存储库:

[machine B]$ git clone machine.a:git/MyProject

这让我克隆了 git 存储库...但我没有看到任何远程分支或标签:

[machine B]$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

无论 git checkout --track -b [branch 的形式是什么] origin/[branch] 我尝试过,我无法在机器 B 上创建一个跟踪远程、最初来自 svn 分支之一的分支...也无法 git svn fetch< /code>、git svn pull 或其他任何我可以尝试从机器 A 上的存储库中提取远程分支和标签的内容。我做错了什么?

I'm struggling to understand how to be able to clone a git repository from Subversion, and then clone that repository to another machine (git-to-git) and still have access to all the original Subversion branches and tags. Here's what I've done, and where I'm running into roadblocks.

First, on machine A, I cloned my Subversion repository into a git repository:

[machine A]$ git svn clone -s http://svn.repo.url/MyProject

That gave me a git repository with the entire history and all the branches and tags of my original Subversion repository:

[machine A]$ git branch -r
* master
  remotes/v1
  remotes/v1.1
  remotes/v1.2
  remotes/test_migration
  remotes/tags/20100104
  remotes/tags/20100308
  remotes/trunk

Now, on machine B, I want to clone that git repository, and still have access to all the original Subversion branches and tags. First, I cloned the repository:

[machine B]$ git clone machine.a:git/MyProject

This got me a clone of the git repository... but I don't see any of the remote branches or tags:

[machine B]$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

No matter what form of git checkout --track -b [branch] origin/[branch] I try, I can't get a branch created on machine B that tracks one of the remote, originally-from-svn branches... nor does a git svn fetch, git svn pull, or anything else I can try pull in the remote branches and tags from the repository on machine A. what am I doing wrong?

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

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

发布评论

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

评论(2

握住你手 2024-09-03 07:10:03

我认为这是因为 git 默认情况下不克隆远程分支。 使用此命令配置克隆

git config --add remote.origin.fetch '+refs/remotes/*:refs/remotes/*'

在执行初始 git fetch 克隆原始存储库之前, 。 查看文档了解详细信息(搜索上面的字符串以查找说明)。

另请阅读“警告”部分。 Subversion 不是 git,并且您必须了解一些重要的差异,否则您损坏您的 git 或 svn 存储库。

I think this is because git doesn't clone remote branches by default. Configure your clone with this command

git config --add remote.origin.fetch '+refs/remotes/*:refs/remotes/*'

before you do the initial git fetch to clone the original repo. See the docs for details (search for the string above to find the explanation).

Also read the section "CAVEAT". Subversion isn't git and there are some important differences which you must understand or you will corrupt either your git or your svn repo.

苄①跕圉湢 2024-09-03 07:10:03

我想评论 这个答案但我还没有被允许,所以我必须发布一个新的。

请注意,克隆 svn 遥控器后,您必须在本地初始化它们,这在文档中进行了描述。但是,引用文档:

请确保使用与服务器上使用的相同的 URL 和 -T/-b/-t 选项。

git config -l | git config -l | git config -l | git config -l | git config -l | git config -l grep remote 将列出主机存储库上所有远程服务器的所有配置(url、分支、忽略等)。输出将类似于:

svn-remote.svn/bbpress.url=http://svn.automattic.com/bbpress/trunk
svn-remote.svn/bbpress.fetch=:refs/remotes/svn/bbpress

然后将其添加到 .gitignore(用 # 注释并用空格替换 =)以供将来使用参考。克隆后,使用 git config --add 和此信息,您将获得这些遥控器的精确副本。

I wanted to comment on this answer but I'm not allowed yet so I have to post a new one.

Pay attention that after cloning the svn remotes you have to init them locally, which is described in the docs. However, citing the docs:

be sure to use the same URL and -T/-b/-t options as were used on server.

git config -l | grep remote will list all configuration for all remotes (url, branches, ignore etc.) on the host repository. The output will be similar to:

svn-remote.svn/bbpress.url=http://svn.automattic.com/bbpress/trunk
svn-remote.svn/bbpress.fetch=:refs/remotes/svn/bbpress

Then add it to, say, .gitignore (commenting with # and replacing = with a space) for future reference. After cloning use git config --add with this info, and you'll get the exact copy of those remotes.

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