如何使用 svn-git (标准布局)然后使用 --bare 选项的 svn-clone 正确保留所有分支

发布于 2025-01-04 20:16:41 字数 549 浏览 1 评论 0原文

我正在尝试将 svn 存储库移动到 git 存储库。我不想再使用 svn,所以我使用无元数据选项。我很好奇为什么在执行 git svn fetch 之后,只有对我的分支创建的远程引用。我正在使用以下命令创建存储库:

git svn init -s --username=$SVNUSER --no-metadata http://URLTOSVN/$REPO
git config svn.authorsfile ../$USERFILE
git svn fetch

运行 fetch 后,如果我查看我拥有的分支:

prompt$ git branch -a
* master
remotes/BRANCH_1
remotes/BRANCH_2
remotes/trunk

我需要 BRANCH_1 和 BRANCH_2 分支,但它似乎没有创建它们。现在,当我使用 --bare 选项克隆它时,我可以将它托管在我的中央存储库中,它会忽略那些远程引用,并且据我所知,我生成的 git 存储库不了解这些分支。我在生成的存储库中需要这些分支。我缺少什么?

I'm attempting to move an svn repository to a git repository. I don't want to use svn anymore so I am using the no-metadata option. I'm curious why, after doing git svn fetch there are only remote refs created to my branches. I'm creating the repo using:

git svn init -s --username=$SVNUSER --no-metadata http://URLTOSVN/$REPO
git config svn.authorsfile ../$USERFILE
git svn fetch

after running the fetch, if I look at the branches I have:

prompt$ git branch -a
* master
remotes/BRANCH_1
remotes/BRANCH_2
remotes/trunk

I need BRANCH_1 and BRANCH_2 branches but it doesn't seem to be creating them. Now when I clone this using the --bare option so I can host it in my central repo it ignores those remote refs and my resulting git repo has no knowledge of those branches as far as I can tell. I need those branches in my resulting repo. What am I missing?

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

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

发布评论

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

评论(1

云雾 2025-01-11 20:16:41

这意味着远程分支可用,但您当前没有将它们作为本地分支。您应该能够使用 git fetch 检索它们:

git fetch origin [remote-branch]:[new-local-branch]

即,

git fetch origin BRANCH_1:BRANCH_1

这是我之前用于将 svn 存储库传输到 git 的 bash 脚本。这将为您在当前目录中运行的计算机上提供一个裸露的 git 存储库:

#!/bin/bash

REPO=$1
REPO_tmp=$REPO"_tmp"
USERFILE="/tmp/users.txt"

echo $REPO " > " $REPO_tmp

mkdir $REPO_tmp
cd $REPO_tmp
echo `pwd`

svn log http://URLTOSVN/$REPO|grep \| | awk 'BEGIN { FS = "|" }; {print $2}' | awk '{print $1 " = " $1 " <" $1 "@domain.com>"}' | sort | uniq > $USERFILE

git svn init http://URLTOSVN/$REPO --no-metadata

git config svn.authorsfile $USERFILE
git svn fetch

cd ..

git clone --bare $REPO_tmp $REPO.git

这还将保留您的 svn 日志历史记录。您可能需要摆弄连接参数,因为我实际上使用的是 svn+ssh,而不是 http。看看我导入并克隆的确实有分支的存储库,我看到这样的示例:

git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/signup

在您的裸存储库中,分支应该只有它们的名称。 ie:

git branch -a
* master
  BRANCH1
  BRANCH2

但是我发现我能够创建一个名为remotes/branch1的分支,所以可能你实际上有一个名称奇怪的本地分支。您可以尝试使用以下命令进行切换:

git checkout remotes/BRANCH_2

This means the remote branches are available but you do not currently have them as local branches. You should be able to retrieve them with a git fetch:

git fetch origin [remote-branch]:[new-local-branch]

i.e.

git fetch origin BRANCH_1:BRANCH_1

Here's a bash script I've used previously for transferring svn repos to git. This will give you a bare git repo on the machine it is run in the current directory:

#!/bin/bash

REPO=$1
REPO_tmp=$REPO"_tmp"
USERFILE="/tmp/users.txt"

echo $REPO " > " $REPO_tmp

mkdir $REPO_tmp
cd $REPO_tmp
echo `pwd`

svn log http://URLTOSVN/$REPO|grep \| | awk 'BEGIN { FS = "|" }; {print $2}' | awk '{print $1 " = " $1 " <" $1 "@domain.com>"}' | sort | uniq > $USERFILE

git svn init http://URLTOSVN/$REPO --no-metadata

git config svn.authorsfile $USERFILE
git svn fetch

cd ..

git clone --bare $REPO_tmp $REPO.git

That will also preserve your svn log history. You will probably need to fiddle with the connection parameters as I actually used svn+ssh, not http. Looking at a repo I imported and then cloned that did have branches I see examples like this:

git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/signup

In your bare repo the branches should just have their name. ie:

git branch -a
* master
  BRANCH1
  BRANCH2

However I found I was able to create a branch named remotes/branch1, so it may be that you actually have local branches that are just weirdly named. You can try swicthing with:

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