Migrate SVN to GIT repository and change author names

Assuming you have the svn and an empty GIT repository, first you need to check out the git repo:

git svn clone https://old.svn.server.com/svnpath

you’ll have the folder named ‘svnpath’ checked out and converted to git format.

The you need to change the author names, we’ll use a feature called ‘filter-branch’ in git to change author names and email addresses:



hput() {
  eval "$1""$2"='$3'

hget() {
    eval echo '${'"$1$2"'#hash}'

# The original SVN usernames
hput originals x1 "Nadalizadeh"
hput originals x2 "sina.bahar"
hput originals x3 "faraz.shamshirdar"
hput originals x4 "elrusho"

# The new GIT Names
hput names x1 "Ali Nadalizadeh"
hput names x2 "Sina Baharlouie"
hput names x3 "Faraz Shamshirdar"
hput names x4 "Soroush Khodaii"

# The new GIT Email Addresses
hput emails x1 "ali@emaildomain1.com"
hput emails x2 "sinabaharlouei@emaildomain1.com"
hput emails x3 "faraz@emaildomain1.com"
hput emails x4 "soroush@emaildomain1.com"

for h in ${!names*}; do
    export oldname=`hget originals $key`;
    export newname=`hget names $key`;
    export newemail=`hget emails $key`;

    echo "Changing $oldname to $newname <$newemail>"
git filter-branch -f --commit-filter '
        if [ "$GIT_AUTHOR_NAME" = "$oldname" ];
                git commit-tree "$@";
                git commit-tree "$@";
        fi' HEAD


Run the above script inside root of your git repository and ofcourse you need to change the names and emails your own values you get from “svn log” and “git log”

Finally push your new git repository to your remote address:

git remote add origin git@new.gitserver.com:git-group/my_repository.git
git push -u origin master
This entry was posted in Technical Docs. Bookmark the permalink.