如何克隆一个git仓库与文献/遥控器所有的分支和标签
1个回答
展开全部
如何克隆回购所有标签和分支? 我发现的唯一方式是镜像的回购协议: $ git clone --mirror git@myhost:mybackup.git
这将创建一个本地mybackup.git目录,它知道所有标签/分支(我得到整个列表),但它不是一个回购协议: $ git checkout mytag
fatal: This operation must be run in a work tree
答案请参考如下代码:
git clone git@myhost:mybackup.git newdirectory
cd newdirectory
git fetch origin refs/remotes/*:refs/remotes/*
git init
现在git branch -a显示我所有的远程分支机构。 我不知道如果git init这里需要的,或者如果它是只需要在git init --barevariant(见下面的shell脚本的输出线),但我相信它损害什么,如果它是没有必要把它留在。 在这个过程中我的主要的原因是为了让我的SVN标签/分支复制过来,而不是只拥有master指着SVNtrunk而不必解析整个SVN历史(很慢的有很多历史,标签和分支的项目)。所以复制了我 git svn init -s " CodeGo.net
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 " CodeGo.net
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
为了创建从现有的混帐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
这将创建一个本地mybackup.git目录,它知道所有标签/分支(我得到整个列表),但它不是一个回购协议: $ git checkout mytag
fatal: This operation must be run in a work tree
答案请参考如下代码:
git clone git@myhost:mybackup.git newdirectory
cd newdirectory
git fetch origin refs/remotes/*:refs/remotes/*
git init
现在git branch -a显示我所有的远程分支机构。 我不知道如果git init这里需要的,或者如果它是只需要在git init --barevariant(见下面的shell脚本的输出线),但我相信它损害什么,如果它是没有必要把它留在。 在这个过程中我的主要的原因是为了让我的SVN标签/分支复制过来,而不是只拥有master指着SVNtrunk而不必解析整个SVN历史(很慢的有很多历史,标签和分支的项目)。所以复制了我 git svn init -s " CodeGo.net
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 " CodeGo.net
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
为了创建从现有的混帐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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询