git-svn: what's the equivalent to `svn switch --relocate`?

后端 未结 8 548
深忆病人
深忆病人 2020-11-29 17:40

An svn repository I\'m mirroring through git-svn has changed URL.

In vanilla svn you\'d just do svn switch --relocate old_url_base new_url_base.

8条回答
  •  广开言路
    2020-11-29 18:26

    git filter-branch

    This script, taken from a blog entry, has worked for me. Supply old and new repo URL as parameter, just like for svn switch --relocate.

    The script calls git filter-branch to replace Subversion URLs in the git-svn-id in the commit messages, updates .git/config, and also updates git-svn metadata by recreating it using git svn rebase. While git svn clone might be the more robust solution, the filter-branch approach works much faster for huge repositories (hours vs. days).

    #!/bin/sh
    
    # Must be called with two command-line args.
    # Example: git-svn-relocate.sh http://old.server https://new.server
    if [ $# -ne 2 ]
    then
      echo "Please invoke this script with two command-line arguments (old and new SVN URLs)."
      exit $E_NO_ARGS
    fi
    
    # Prepare URLs for regex search and replace.
    oldUrl=`echo $1 | awk '{gsub("[\\\.]", "\\\\\\\&");print}'`
    newUrl=`echo $2 | awk '{gsub("[\\\&]", "\\\\\\\&");print}'`
    
    filter="sed \"s|^git-svn-id: $oldUrl|git-svn-id: $newUrl|g\""
    git filter-branch --msg-filter "$filter" -- --all
    
    sed -i.backup -e "s|$oldUrl|$newUrl|g" .git/config
    
    rm -rf .git/svn
    git svn rebase
    

提交回复
热议问题