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</p>
<p>if [ -f ~/tmp/git2svn.lock ]; then<br />
 echo &quot;git2svn is already processing...&quot;<br />
 exit 0<br />
else<br />
 touch ~/tmp/git2svn.lock<br />
fi</p>
<p>echo &quot;$(date --iso-8601=minutes) === git2svn.sh sync repos ===&quot;</p>
<p>for repo in $HOME/repos/* ; do<br />
 cd &quot;${repo}&quot;</p>
<p> git checkout -b svn/git-svn<br />
 git checkout svn/git-svn<br />
 git svn fetch<br />
 git svn rebase<br />
 git checkout master<br />
 git pull --rebase upstream master<br />
 git checkout svn/git-svn<br />
 MESSAGE=`git log --pretty=format:'%ai | %B [%an]' HEAD..master`<br />
 git merge --no-ff --no-log -m &quot;${MESSAGE}&quot; master<br />
 git svn dcommit<br />
 git checkout master<br />
 git merge svn/git-svn<br />
 git push upstream master</p>
<p>done</p>
<p>rm ~/tmp/git2svn.lock<br />

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.