You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Git合并feature-new到master后git svn info元数据异常,如何修复?

问题

我用git svn从老旧SVN服务器拉取了项目,合并前git svn info显示:

  • master指向https://svn-server/repos/myProject
  • feature-new指向https://svn-server/repos/branches/myProject

但将feature-new合并到master后,master的SVN映射地址变成了错误的https://svn-server/repos/myProject/myProject/myBranch。

SVN仓库结构:

  • trunk:https://svn-server/repos/myProject
  • branch:https://svn-server/repos/branches/myProject

拉取步骤如下:

  1. SVN克隆初始化:
git svn init https://svn-server/repos --trunk=myProject --branches=branches/{myProject} myProject
  1. 设置作者映射文件:
git config svn.authorsfile ~/authors.txt
  1. 编辑.git/config内容:
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false  
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[svn-remote "svn"]
        url = https://svn-server/repos/myProject
        fetch = myProject:refs/remotes/git-svn/trunk
        branches = branches/{myProject}/*:refs/remotes/feature-new/*
[svn]
        authorsfile = ~/authors.txt
  1. 拉取代码:
git svn fetch
  1. 确认远程分支:
git branch -r

输出结果:

feature-new/myProject
git-svn/trunk
  1. 检出并创建本地分支:
git checkout feature-new/myProject
git switch -c feature-new
解决方案

1. 修正.git/config中的SVN远程配置

你的配置里svn-remote的url和分支映射存在路径嵌套错误,是导致合并后映射混乱的核心原因。修改为以下内容:

[svn-remote "svn"]
        url = https://svn-server/repos
        fetch = myProject:refs/remotes/git-svn/trunk
        branches = branches/myProject:refs/remotes/git-svn/branches/feature-new
  • 将url改回SVN仓库根地址,而非trunk的子路径
  • 调整branches映射规则,直接指向SVN分支的实际路径,避免通配符引发的路径嵌套问题

2. 重置master分支的SVN映射

合并后master的SVN元数据已混乱,需要重新绑定正确的trunk地址:

# 切换到master分支
git checkout master
# 重置master到git-svn/trunk的最新提交
git reset --hard git-svn/trunk
# 重新设置master的SVN追踪信息
git config branch.master.svn-remote svn
git config branch.master.merge refs/remotes/git-svn/trunk

3. 验证修复结果

运行以下命令确认映射是否恢复正确:

git svn info

输出的URL应显示为https://svn-server/repos/myProject,即正确的trunk地址。

4. 后续合并注意事项

以后从feature-new合并到master时,需先用git svn rebase同步SVN远程分支,再进行合并,避免映射再次混乱:

# 切换到feature-new分支同步SVN变更
git checkout feature-new
git svn rebase
# 切换到master同步trunk
git checkout master
git svn rebase
# 合并feature-new到master
git merge feature-new

内容的提问来源于stack exchange,提问作者chiahao

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 20:22:02