经过大量搜索,我终于找到了答案......
git clone git@myhost:mybackup.git newdirectory
cd newdirectory
git fetch origin refs/remotes/*:refs/remotes/*
git init
现在 agit branch -a
显示了我所有的远程分支。
我不确定git init
这里是否需要它,或者是否仅在git init --bare
变体中需要它(请参阅下面的 shell 脚本中注释掉的行),但我确信如果不需要它,将它留在里面没有任何害处。
我这样做的主要原因是复制我的 SVN 标签/分支,而不是仅仅master
指向 SVNtrunk
而不必解析整个 SVN 历史(对于具有大量历史、标签和分支的项目来说非常慢)。所以要复制我的 SVN 信息:
git svn init -s "svn://mysvnhost/mysvnrepo/myproject"
git svn fetch
git checkout master
为了加快这个过程,我创建了一个 shell 脚本:
#!/bin/sh
#
# git-clone-svn-based-repo.sh:
#
# clones a git-svn based repo including all SVN commits without pounding
# the SVN server for hours (just a quick refresh taking seconds)
#
usage_exit ()
{
echo "Usage: $0 <git-repo> <dest-directory> <svn-project>"
exit 1
}
if ! git ls-remote "$1" > /dev/null 2>&1
then
echo "No git repo found at: $1"
usage_exit
fi
if [ -r "$2" ]
then
echo "File or directory already exists: $2"
usage_exit
fi
if ! svn ls "$3" 2> /dev/null | grep -q trunk
then
echo "No SVN project found at: $3"
usage_exit
fi
# create new bare git repo
mkdir "$2"
cd "$2"
git init --bare .git
# fetch everything from backup
git remote add backup "$1"
git fetch backup refs/remotes/*:refs/remotes/*
git fetch backup refs/heads/*:refs/heads/*
git fetch backup refs/tags/*:refs/tags/*
# disable future fetching from backup
# setup to push all remote refs to backup by default
git config remote.backup.fetch do_not_fetch_from_backup
git config remote.backup.push '+refs/remotes/*:refs/remotes/*'
# initialize git repo to usable (non-bare) state
git init
# update SVN references
git svn init -s "svn://svn.crc-corp.com/carsrepository/$3"
git config svn.authorsfile $HOME/projects/authors.txt
git svn fetch
# update master to current SVN trunk
git checkout master
git svn rebase
# update ignore properties from SVN
git svn show-ignore >> .git/info/exclude
为了从现有的 git SVN 存储库创建这样的备份:
# create a bare backup repo at git@myhost:mybackup.git
git remote add backup git@myhost:mybackup.git
git config remote.backup.fetch do_not_fetch_from_backup
git config remote.backup.push '+refs/remotes/*:refs/remotes/*'
git push backup