Converting a subversion repo to git

This is not finished. It has been posted for review. When this paragraph is gone, the post is finished.

I’ve wanted to convert my subversion repos to git for years. It’s never been a high priority. But here we go.

First, I created a local temporary and insure subversion repo with a copy of my real repo. This allows me to mess up and not affect the real repo. I’m sure nothing I’m doing should affect the subversion repo, but this approach ensures that outcome.

In this post:

  • FreeBSD 14.1
  • subversion 1.14.4
  • git 2.47.1
  • git-svn 2.47.1 – installing avoids the git: ‘svn’ is not a git command. See ‘git –help’. error
  • git-filter-repo 2.47.0 – versatile tool for rewriting history

I’m basing this blog post on a freshports issue which works on the same goal.

I’m following Migrating from SVN to Git: Step-by-Step Guide – don’t get confused by the use of two different names for the authors file. Sometimes it’s authors-transform.txt, then it is author-transformed.txt – they could do a better job explaining that.

Start by git cloning your subversion repo

I ran this command. The new git repo will be created in the current directory and will be within the ports directory.

[14:40 mydev dvl ~/src/subversion-to-git/ports-git] % git svn clone svn://127.0.0.16/websites/ports --authors-file=author-transformed.txt ports
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint:   git config --global init.defaultBranch 
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint:   git branch -m 
Initialized empty Git repository in /usr/home/dvl/src/subversion-to-git/ports-git/ports/.git/
W: Ignoring error from SVN, path probably does not exist: (160013): Filesystem has no item: File not found: revision 100, path '/ports'
W: Do not be alarmed at the above message git-svn is just searching aggressively for old history.
This may take a while on large repositories
Checked Ahrough Makefile
        A       distinfo
        A       files/fruity.config.inc.in
        A       files/patch-includes-config.inc.in
...
        A       url-highlight/files/pkg-message.in
        A       url-highlight/files/pkg-opts
        A       url-highlight/pkg-descr
        A       url-highlight/pkg-plist
r20709 = e25bad7baf6fbd19fc4ae17c2080426f7acc2842 (refs/remotes/git-svn)
Checked out HEAD:
  svn://127.0.0.16/websites/ports r20709
creating empty directory: freshports-ingress-metaport/files
creating empty directory: py-markdown/files

Let’s see what I have:

[14:43 mydev dvl ~/src/subversion-to-git/ports-git] % ls -l
total 9
-rw-r--r--   1 dvl dvl 76 2024.12.24 14:38 author-transformed.txt
drwxr-xr-x  41 dvl dvl 43 2024.12.24 14:43 ports/
[14:47 mydev dvl ~/src/subversion-to-git/ports-git] % cd ports 
[14:47 mydev dvl ~/src/subversion-to-git/ports-git/ports] % ls
FreshPorts-Scripts-Dependencies/            freshsource-www/
GIDs                                        fruity/
SamDruckerClientShell/                      p5-FreshPorts-Modules-Dependencies/
UIDs                                        p5-freshports-modules/
bsdcan-pgcon-dependencies/                  p5-freshports-scripts/
default_vhost_nginx/                        p5-freshports-verify/
dvl-librenms-dependencies-client/           pgeu-system/
dvl-librenms-dependencies-server/           phorum/
freebsddiary-www/                           py-Jinja2/
freshports-database/                        py-MarkupSafe/
freshports-freshports/                      py-freshports-fp-listen/
freshports-helper-scripts/                  py-freshports-git-proc-commit/
freshports-ingress/                         py-freshports-git-proc-commit-dependencies/
freshports-ingress-metaport/                py-markdown/
freshports-periodics/                       py-packages-import/
freshports-www/                             samdruckerserver/
freshports-www-caching/                     services-dependencies/
freshports-www-dependencies/                url-highlight/
freshports-www-offline/                     wordpress-dependencies/
freshports-www-packages/                    wordpress-dependencies-php81/

That looks OK to me. So does this:

commit e25bad7baf6fbd19fc4ae17c2080426f7acc2842 (HEAD -> master, git-svn)
Author: Dan Langille 
Date:   Tue Dec 24 13:25:58 2024 +0000

    I think I created this when testing new url highlighting solutions.
    
    
    git-svn-id: svn://127.0.0.16/websites/ports@20709 e9903129-21d8-e211-989e-002590a4cdd4

commit 2eac89f163a4f589815c381c88d3d52de138b356
Author: Dan Langille 
Date:   Tue Dec 24 13:24:28 2024 +0000

    add USES, p5-Email-Address-XS
    
    git-svn-id: svn://127.0.0.16/websites/ports@20708 e9903129-21d8-e211-989e-002590a4cdd4

commit 91e90e818f54b6ea42baaa09b90e780ac837dc00
....

I had already created a repo on Github. I added in the remote:

[15:12 mydev dvl ~/src/subversion-to-git/ports-git/ports] % git remote add origin git@github.com:FreshPorts/ports.git
[15:14 mydev dvl ~/src/subversion-to-git/ports-git/ports] % git remote -v                                            
origin  git@github.com:FreshPorts/ports.git (fetch)
origin  git@github.com:FreshPorts/ports.git (push)

I tried this:

[15:14 mydev dvl ~/src/subversion-to-git/ports-git/ports] % git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master

To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.

And then this:

[15:14 mydev dvl ~/src/subversion-to-git/ports-git/ports] % git push --set-upstream origin main
error: src refspec main does not match any
error: failed to push some refs to 'github.com:FreshPorts/ports.git'

And finally:

[15:14 mydev dvl ~/src/subversion-to-git/ports-git/ports] % git push --set-upstream origin master
Enumerating objects: 4052, done.
Counting objects: 100% (4052/4052), done.
Delta compression using up to 72 threads
Compressing objects: 100% (4004/4004), done.
Writing objects: 100% (4052/4052), 643.83 KiB | 2.00 MiB/s, done.
Total 4052 (delta 1876), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (1876/1876), done.
remote: 
remote: Create a pull request for 'master' on GitHub by visiting:
remote:      https://github.com/FreshPorts/ports/pull/new/master
remote: 
To github.com:FreshPorts/ports.git
 * [new branch]      master -> master
branch 'master' set up to track 'origin/master'.
[15:14 mydev dvl ~/src/subversion-to-git/ports-git/ports] % git push
Everything up-to-date
[15:16 mydev dvl ~/src/subversion-to-git/ports-git/ports] % 

That repo is still private. There is more work to be done.

Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive

Leave a Comment

Scroll to Top