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

使用svn2git迁移至Git仓库时,如何保留原SVN版本号?

Keeping Original SVN Revision Numbers in Your Migrated Git Repository

Absolutely! You can totally retain those original SVN revision numbers in your newly migrated Git repository, and there are a few straightforward, reliable approaches to make this happen—pick the one that fits how your team wants to access that historical info.

Option 1: Embed SVN Revisions Directly in Git Commit Messages

This is the easiest, most out-of-the-box solution since svn2git has built-in support for it. When you run your migration command, just add the --add-metadata flag:

svn2git https://your-svn-repo-url.com/project --add-metadata

Every Git commit generated by the migration will automatically have a line at the end of its message that looks like:

git-svn-id: https://your-svn-repo-url.com/project@1234 5a1b2c3d...

The @1234 here is exactly the original SVN revision number. Anyone checking the commit history will immediately see which SVN revision maps to that Git commit.

If you want a cleaner format (like just SVN Revision: 1234), you can tweak svn2git's commit template, but --add-metadata is the no-fuss default that works for most teams.

If you don't want to clutter up your commit messages, Git Notes are perfect—they let you attach extra metadata (like SVN revision numbers) to commits without modifying the commits themselves.

  1. First run your basic svn2git migration (skip the --add-metadata flag if you want clean commit messages)
  2. Run this command to link the current HEAD commit to its SVN revision:
git svn fetch
git notes add -m "SVN Revision: $(git svn find-rev $(git rev-parse HEAD))" HEAD

To batch-add notes for all commits, use a simple shell script:

git log --pretty=format:"%H" | while read commit_hash; do
    svn_rev=$(git svn find-rev $commit_hash)
    if [ -n "$svn_rev" ]; then
        git notes add -m "SVN Revision: $svn_rev" $commit_hash
    fi
done

To see the SVN revision alongside commit details, use:

git log --notes

Option 3: Create Git Tags for Critical SVN Revisions

If your SVN repo had key milestones (like release versions, hotfixes), you can create Git tags that include the SVN revision number to make those easy to find later.

  1. First find the Git commit hash that maps to your target SVN revision:
git svn find-rev r1234
  1. Create an annotated tag for that commit:
git tag -a svn-r1234-release <commit-hash-you-found> -m "Maps to SVN revision r1234 (v1.2.3 release)"

This way, your team can quickly jump to important historical versions using the tag, and the SVN revision is clearly labeled.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 11:14:17