BI-directional Git to svn sync script

Veröffentlicht am

Something that I did create over some years – there is nothing similar that I have found as a open/OSS solution, so therefore I’d like to share it.

#!/bin/bash

if [ -f ~/tmp/git2svn.lock ]; then
 echo "git2svn is already processing..."
 exit 0
else
 touch ~/tmp/git2svn.lock
fi

echo "$(date --iso-8601=minutes) === git2svn.sh sync repos ==="

for repo in $HOME/repos/* ; do
 cd "${repo}"

 git checkout -b svn/git-svn
 git checkout svn/git-svn
 git svn fetch
 git svn rebase
 git checkout master
 git pull --rebase upstream master
 git checkout svn/git-svn
 MESSAGE=`git log --pretty=format:'%ai | %B [%an]' HEAD..master`
 git merge --no-ff --no-log -m "${MESSAGE}" master
 git svn dcommit
 git checkout master
 git merge svn/git-svn
 git push upstream master

done

rm ~/tmp/git2svn.lock

The trick is to use two different local only branches in which you do the merging vice versa. Just using one branch like master will cause serious issues.

3 Gedanken zu „BI-directional Git to svn sync script“

  1. Hi Tobias,
    I have this situation that I would like to handle.

    We are working with SVN but we would like to switch to Git and keep to update the SVN repo.
    Can you clarify your script with an example?

    Thanks,
    Luigi

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.