如何使用 git-svn 将具有非法分支名称的 svn 存储库转换为 git?

发布于 2024-11-16 07:29:51 字数 436 浏览 1 评论 0原文

我正在尝试使用 git-svn 将公司 svn 存储库加载到 git 中,但遗憾的是我的一位同事创建了一个分支名称中包含非法字符 (\) 的分支。现在,当我尝试导入整个历史记录时,git 退出并出现错误:

fatal: Cannot lock the ref 'refs/remotes/feature-\\-bar'.
update-ref -m r4 refs/remotes/feature-\\-bar 471d9622546803b3712a436c2e2ed6b1490c829a: command returned error: 128

我可以不使用分支,因为无论如何它都已经过去了,但我不想丢失所有历史记录,直到分支被合并。我尝试了 --ignore-path 选项,但我无法让它工作,主要是因为我怀疑它只寻址分支/主干路径内的路径(??)。 有谁知道解决这个问题的方法吗?

I am trying to load out company svn repo into git using git-svn, but sadly one of my coworkers created a branch with illegal characters (\) in the branch name. Now, when I'm trying to import the whole history, git exits with an error:

fatal: Cannot lock the ref 'refs/remotes/feature-\\-bar'.
update-ref -m r4 refs/remotes/feature-\\-bar 471d9622546803b3712a436c2e2ed6b1490c829a: command returned error: 128

I could do without the branch since it is way in the past anyway, but I do not want to loose all the history up to the point where the branch was merged. I tried the --ignore-path option, but I cannot get it to work, mainly because I suspect it only addresses paths inside the branch/trunk path (??).
Does anyone know by any chance a way to resolve this issue?

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

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

发布评论

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

评论(2

飞烟轻若梦 2024-11-23 07:29:51

我也必须忽略一些分支,因为它们使用了我无法使用 git svn 获取的非法字符(在我的例子中,字符是 :/ )。

解决方案 1:为每个分支手动添加额外的 svn 存储库

使用 git svn init -s [svn-repository-url] 初始化存储库后,我在 中评论了分支配置>.git/config out:

[svn-remote "svn"]
    url = [svn-base-url]
    fetch = [project-name]/trunk:refs/remotes/trunk
    #branches = [project-name]/branches/*:refs/remotes/*
    tags = [project-name]/tags/*:refs/remotes/tags/*

为了稍后添加分支,我将通过为每个分支添加新的 svn 位置来完成此操作,例如

[svn-remote "svn-your-branch"]
    url = [svn-base-url]
    fetch = [project-name]/branches/your-branch:refs/remotes/your-branch

来源:Git SVN 忽略路径如何工作(忽略每日构建标签)?或使用一些实际配置,例如http://www.dmo.ca/blog/20070608113513/

解决方案 2:明确在配置中声明您喜欢的分支

您可以在.git/config中定义要获取的分支:

[svn-remote "svn"]
    url = [svn-base-url]
    fetch = [project-name]/trunk:refs/remotes/trunk
    branches = [project-name]/branches/{your-branch-1|your-branch-2}:refs/remotes/*
    tags = [project-name]/tags/*:refs/remotes/tags/*

如果可以安全的话在从 svn 签出所有内容后添加分支,我会更喜欢这个解决方案。

来源:https://stackoverflow.com/a/3844508/709431

为什么忽略路径不起作用?

根据 http://go-dvcs.atlassian.com/display/aod/Advanced+git-svn+options git svn --ignore-paths 仅忽略提交的内容。因此,它仍然会为分支名称创建一个引用。如果分支名称包含非法字符,则此操作会失败。 (此外,与您的假设相反,ignore-paths 匹配除 URL 部分之外的所有内容,例如使用上面的配置,例如 project-name/branches/your-branch-1代码>.)

I had to do ignore some branches, too, because they were using illegal characters I could not fetch with git svn (in my case the characters were : and /).

Solution 1: Manually add additional svn repositories for each branch

After initialising your repository with git svn init -s [svn-repository-url] I commented the branch configuration in .git/config out:

[svn-remote "svn"]
    url = [svn-base-url]
    fetch = [project-name]/trunk:refs/remotes/trunk
    #branches = [project-name]/branches/*:refs/remotes/*
    tags = [project-name]/tags/*:refs/remotes/tags/*

To add branches later on, I will do this by adding new svn locations for each branch, e.g.

[svn-remote "svn-your-branch"]
    url = [svn-base-url]
    fetch = [project-name]/branches/your-branch:refs/remotes/your-branch

Source: How do Git SVN ignore-paths work (ignoring daily build tags)? or with some actual configuration e.g. http://www.dmo.ca/blog/20070608113513/

Solution 2: Explicitly state the branches you like in your configuration

You can define the branches to fetch in .git/config:

[svn-remote "svn"]
    url = [svn-base-url]
    fetch = [project-name]/trunk:refs/remotes/trunk
    branches = [project-name]/branches/{your-branch-1|your-branch-2}:refs/remotes/*
    tags = [project-name]/tags/*:refs/remotes/tags/*

If it is safe to add branches later on after having checkout out everything from svn, I will prefer this solution.

Source: https://stackoverflow.com/a/3844508/709431

Why does ignore-paths not work?

According to http://go-dvcs.atlassian.com/display/aod/Advanced+git-svn+options git svn --ignore-paths only ignores the content of the commits. Thus, it will still create a ref for the branch name. This fails, if the branch name contains illegal characters. (Additionally, contrary to your assumption, ignore-paths matches everything excluding the URL-part, e.g. with the configuration from above things like project-name/branches/your-branch-1.)

戏剧牡丹亭 2024-11-23 07:29:51

我会在当前任何分支的开头启动 git 存储库 - 手动使分支名称适合 git。对于较旧的历史记录,需要时以这种方式导入。有时,导入 svn 历史记录的痛苦是不值得的,因为它遵循完全不同的机制。

I would start the git repo at the head of whatever branches are current - manually making the names of branches git-friendly. For older history import this way when needed. Sometimes it's just not worth the pain of importing svn history which follows a totally different mechanism all together.

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