git und SVN

Szenario: Ein vorhandenes SVN Repository soll auf einen git Server gehostet werden und dann dort weiterentwickelt werden.

Eine virtuelle Maschine auf der diese Anleitung erstellt wurde liegt auf dem Laptop im Verzeichnis D:\vm_images\TQ ubuntu - svn git test.

Zum Testen wurde ein SVN Server aufgesetzt (nach Anleitung: https://help.ubuntu.com/community/Subversion). Zuerst muss subversion und apache2 webserver (Wird nur für http gebraucht) installiert werden.

tq@ubuntu:~$ sudo apt-get update
tq@ubuntu:~$ sudo apt-get install apache2 subversion

Eine Gruppe für subversion erstellen und eigenen User und www-data (webserver user) zu dieser Gruppe hinzufügen:

tq@ubuntu:~$ sudo addgroup subversion
tq@ubuntu:~$ sudo adduser tq subversion
tq@ubuntu:~$ sudo adduser www-data subversion

Ein Wurzelverzeichnis für die SVN Repositories erstellen:

tq@ubuntu:~$ sudo mkdir /srv/svn
tq@ubuntu:~$ cd /srv/svn
tq@ubuntu:/srv/svn$ sudo chown root:subversion .
tq@ubuntu:/srv/svn$ sudo chmod g+w .

SVN Repository erstellen:

tq@ubuntu:/srv/svn$ sudo svnadmin create /srv/svn/testproject/
tq@ubuntu:/srv/svn$ sudo chown -R www-data:subversion testproject/
tq@ubuntu:/srv/svn$ sudo chmod -R g+rws testproject/

Verzeichnis für Arbeitskopie erstellen:

tq@ubuntu:~$ mkdir ~/src
tq@ubuntu:~$ cd $_

Jetzt kann man schon mit dem file: Protokoll das Repository auschecken:

tq@ubuntu:~/src$ svn co file:///srv/svn/testproject/

git-svn installieren und das SVN Repository in git überführen:

tq@ubuntu:~$ sudo apt-get install git-core git-svn
tq@ubuntu:~$ cd src
tq@ubuntu:~/src$ git svn clone file:///srv/svn/testproject/ gitsvntest

Änderung im SVN machen und commiten:

tq@ubuntu:~/src/testproject$ echo "svn edit"> a
tq@ubuntu:~/src/testproject$ svn st
M       a
tq@ubuntu:~/src/testproject$ svn ci -m "svn edit"
tq@ubuntu:~/src/testproject$ svn up
At revision 3.

Die Änderungen werden nun per git-svn übernommen:

tq@ubuntu:~/src/gitsvntest$ git svn rebase
	M	a
r3 = 6990c465a85965e235773c4a8d50d8216f9b4318 (refs/remotes/git-svn)
First, rewinding head to replay your work on top of it...
Fast-forwarded master to refs/remotes/git-svn.
tq@ubuntu:~/src/gitsvntest$ git log -n 1
commit 6990c465a85965e235773c4a8d50d8216f9b4318
Author: tq <tq@7b2558ac-5255-4b2b-b089-ca010ff40692>
Date:   Fri Dec 16 10:05:09 2011 +0000
 
    svn edit
 
 
    git-svn-id: file:///srv/svn/testproject@3 7b2558ac-5255-4b2b-b089-ca010ff406

Änderung im svn Projekt:

tq@ubuntu:~/src/testproject$ echo "svn2 änderung" >> a
tq@ubuntu:~/src/testproject$ svn ci -m "svn2 edit"

Änderung im git Projekt:

tq@ubuntu:~/src/gitsvntest$ echo "git änderung" >> a
tq@ubuntu:~/src/gitsvntest$ git commit -a -m "git änderung"

Jetzt der import per git-svn:

tq@ubuntu:~/src/gitsvntest$ git svn rebase
	M	a
r4 = ca0e45a8d1d89667f2347280ff230176178c1d43 (refs/remotes/git-svn)
First, rewinding head to replay your work on top of it...
Applying: git änderung
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging a
CONFLICT (content): Merge conflict in a
Failed to merge in the changes.
Patch failed at 0001 git änderung
 
When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".
 
rebase refs/remotes/git-svn: command returned error: 1
 
tq@ubuntu:~/src/gitsvntest$ ls
a  src
tq@ubuntu:~/src/gitsvntest$ cat a
svn edit
<<<<<<< HEAD
svn2 änderung
=======
git änderung
>>>>>>> git änderung
tq@ubuntu:~/src/gitsvntest$ vi a
tq@ubuntu:~/src/gitsvntest$ git rebase --continue
You must edit all merge conflicts and then
mark them as resolved using git add
tq@ubuntu:~/src/gitsvntest$ git add a
tq@ubuntu:~/src/gitsvntest$ git rebase --continue
Applying: git änderung

Jetzt muss noch irgendwie die Änderung ins SVN

tq@ubuntu:~/src/gitsvntest$ git svn dcommit
Committing to file:///srv/svn/testproject ...
	M	a
Committed r5
	M	a
r5 = d5b4eb0575010ee38094e5221639865d3f13d9a7 (refs/remotes/git-svn)
No changes between current HEAD and refs/remotes/git-svn
Resetting to the latest refs/remotes/git-svn
tq@ubuntu:~/src/testproject$ svn up
U    a
Updated to revision 5.
tq@ubuntu:~/src/testproject$ cat a
svn edit
svn2 änderung
git änderung
tq@ubuntu:~$ cd ~/src/
tq@ubuntu:~/src$ git svn clone --username twaldecker https://svn.reccoware.de/tq/system/trunk tq

Dauert sehr lange. Um nur die letzten paar revisionen zu importieren kann man folgendes Kommando verwenden:

tq@ubuntu:~/src$ git svn clone -r 140:HEAD --username twaldecker https://svn.reccoware.de/tq/system/trunk tq

Disclaimer
TQ-Systems GmbH provides the Board Support Packages (BSP) free of charge. The software included in the shipment has been configured individually for the starter kits. The software is only intended to evaluate the module. The use of the Board Support Packages (BSP) is only allowed within the scope of functionality described by TQ-Systems GmbH. TQ-Systems GmbH does not accept any liability for all further changes of the Board Support Package and for any damage resulting from its use.