Skip to content

Instantly share code, notes, and snippets.

@agutenkunst
Last active November 12, 2019 05:49
Show Gist options
  • Save agutenkunst/6049d5a137a8ab0c25d974a16e67787a to your computer and use it in GitHub Desktop.
Save agutenkunst/6049d5a137a8ab0c25d974a16e67787a to your computer and use it in GitHub Desktop.
Convert SVN to Git - Basic Demo

Svn2GitBasic Demo

Setup

Install requirements

  • sudo apt install subversion git

Install docker

sudo snap install docker
sudo groupadd docker
sudo usermod -aG docker $USER

restart for changes to be effectiv.

Start a SVN server via docker

Start the svn-server with

docker run -d -p 80:80 --name svn-server krisdavison/svn-server:v3.0

The default access preconfigure is user - password.

Check that it is by looking at (http://localhost/svn/)[http://localhost/svn/].

Add some users

Add two (or more)n users by runnning

docker exec -it svn-server htpasswd -b -c /etc/subversion/passwd user1 password1
docker exec -it svn-server htpasswd -b -c /etc/subversion/passwd user2 password2

afterward restart the apache inside the docker for the changes to be effective

docker exec -it svn-server /etc/init.d/apache2 reload

Checkout the repo

svn checkout http://localhost/svn/SampleProject/ --username user

Checked out revision 0.

Create some first commits.

Create file and fill it with content and commit it

echo "This is the content of file1 on the first commit." >> file1.txt
svn add file1.txt
svn commit -m "Initial commit" --username user

echo "This is the content of file2 on the second commit." >> file2.txt
svn add file2.txt
svn commit -m "Second commit" --username user1

echo "This is the content of file3 on the third commit." >> file3.txt
svn add file3.txt
svn commit -m "Third commit" --username user2

Check that the commits were successful

svn update
svn log

which should show the 3 commits

Convert the repo into a git repo

git svn clone --username user http://localhost/svn/SampleProject ../git-repo

Check that the repo contains the commits

cd ../git-repo
git log

which should show something like

Author: user <user@d9e2b561-1f1f-4448-a533-1550bdb452c2>
Date:   Mon Nov 11 11:56:38 2019 +0000

    Initial commit
    
    git-svn-id: http://localhost/svn/SampleProject@1 d9e2b561-1f1f-4448-a533-1550bdb452c2

as you can see the number behind the [@] indicates the revision number.

Install a alias to find a commit related to a svn revision

Edit or create your ~/.gitconfig to contain the lines

[alias]
	find-svn-revision = "!git log --name-status --grep \"git-svn-id.*@$1\" #"

now

git find-svn-revision 2

will show the commit which originated from the svn revision 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment