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

如何正确迁移非标准布局SVN仓库至Git并保留历史记录

Alright, let's work through this non-standard SVN to Git migration—your repository's layout is a bit tricky since branches live directly under the root (no standard branches/ folder) and each branch has its own unique subdirectory structure. That's why your initial git svn clone only picked up partial branch content. Here's how to fix this and preserve every bit of your history:

Step 1: Clone the entire SVN repo without filters

First, we'll pull down the full SVN repository to ensure we have access to all history, without restricting it to specific trunk/branch paths upfront. Run this command:

git svn clone -r623:HEAD http://svnURL/XYZProject --username barodia --authors-file=authors.txt --no-minimize-url --stdlayout=false

The --stdlayout=false flag tells git-svn not to assume the standard trunk/branches/tags structure, so it'll grab everything in the repo as-is initially.

Step 2: Map each branch to its actual SVN path

Next, we need to tell git-svn exactly which SVN paths correspond to your Git branches. Open the .git/config file in your cloned repo and locate the [svn-remote "svn"] section. Update it to include explicit mappings for each VF branch, pointing to their true code root in SVN:

[svn-remote "svn"]
    url = http://svnURL/XYZProject
    fetch = trunk:refs/remotes/origin/trunk
    branches = VF1/trunk_vf1:refs/remotes/origin/VF1
    branches = VF2:refs/remotes/origin/VF2
    branches = VF3:refs/remotes/origin/VF3
    authorsfile = authors.txt
  • VF1: Maps the actual code root VF1/trunk_vf1/ to Git's remote branch origin/VF1
  • VF2: Maps the entire VF2/ path (since its src/ and doc/ are direct children) to origin/VF2
  • VF3: Maps the full VF3/ path (including all its subdirectories) to origin/VF3—if only specific subdirs belong to the branch, adjust this path (e.g., VF3/trunk_vf3 if that's the main code directory)

Step 3: Fetch the complete branch histories

With the mappings set, run this command to pull in all the commit history for each mapped branch:

git svn fetch

This will sync all SVN commits for each branch path and link them to the corresponding Git remote branches.

Step 4: Create local Git branches from the remote refs

Once the fetch finishes, convert the remote SVN refs into local Git branches you can work with:

git checkout -b VF1 origin/VF1
git checkout -b VF2 origin/VF2
git checkout -b VF3 origin/VF3
git checkout -b trunk origin/trunk

Step 5: Verify everything is correct

Double-check that each branch has the right file structure and full history:

# Check VF1
git checkout VF1
ls -la  # Should show the contents of SVN's VF1/trunk_vf1
git log  # Should display all commits related to VF1/trunk_vf1

# Repeat these checks for VF2, VF3, and trunk to confirm

Troubleshooting Notes

  • If you notice missing history, double-check your branch path mappings in .git/config—a small typo can throw off the sync.
  • If a branch has disjoint history (e.g., VF1 was copied from trunk at some point), git-svn should handle this automatically, but you can run git svn rebase on the branch if needed to fix gaps.
  • If you already have an existing clone, skip Step 1, just update .git/config, and run git svn fetch to pull in the missing branch history.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 07:46:10