2013-08-02 8 views
7

私はSVNのレポから作成されたローカルGitのレポを持っている:refs/remotesのすべてのブランチとタグを使ってgit repoをクローンする方法は?

$ git svn clone -s svn:... 

私は、バックアップ、リモートを作成し、それにすべてをプッシュ:

$ git remote add backup [email protected]:mybackup.git 
$ git push --mirror backup 

、私はからクローンを作成しようとすると、私のバックアップ、それはすべてのsvnタグと支店がありません。

$ git clone [email protected]:mybackup.git 
$ cd mybackup 
$ git branch -a 
* master 
    origin 
    remotes/origin/HEAD -> origin/master 
    remotes/origin/master 

すべてのタグとブランチを使用してレポをクローンするにはどうすればよいですか?

私が見つけた唯一の方法はレポミラーリングすることである。(私は、リスト全体を取得するにはタブ補完を使用することができます)。これは、ローカルmybackup.gitディレクトリを作成します

$ git clone --mirror [email protected]:mybackup.git 

、およそすべてのタグ/枝を知っているが、有効な使用可能なレポではありません:

$ git checkout mytag 
fatal: This operation must be run in a work tree 

本当にすべてのブランチ/タグでレポをクローンするには、コマンドラインオプションが必要ですか?

私はここでいくつかの関連する質問を見つけましたが、答えのどれもこの状況では機能しません。私の違いは、私のクローンが--mirrorで作成されたということですか?

+0

詳細:私の新しいクローンが知っているブランチは、私のバックアップの 'refs/heads'ディレクトリにありますが、見つからないものは' refs/remotes'にあります。(奇妙なことに 'backup'も'refs/remotes' - 私が仮定している' --mirror'の副作用)。 –

答えて

7

git clone --mirror [email protected]:mybackup.git 私は、あなたのコマンドはmybackup.gitディレクトリを作成したのはこの1知っている見つかった1:

mkdir mybackup 
mv mybackup.git mybackup/.git 
cd mybackup 
git init 

ここには完全な作業ディレクトリがあります。

また、このページで読むことができるよう:https://git.wiki.kernel.org/index.php/Git_FAQ#How_do_I_clone_a_repository_with_all_remotely_tracked_branches.3F

git clone --mirror [email protected]:mybackup.git mybackup/.git 
cd mybackup 
git config --bool core.bare false 

私は両方が最後の行まで等価であると思うし、おそらくコマンドgit config --bool core.bare falsegit initを行うよりもきれいです。

--mirrorは、作業用リポジトリではなく、裸のリポジトリを作成するため、作業用リポジトリに変換する必要があります。

+0

ありがとうございます。私のソリューションをこのように退職させると、よりシンプルになります。その後、新しいリポジトリにSVNをフックするだけで済みます。 –

2

検索の多くの後、私はようやく答えを見つけた...

git clone [email protected]:mybackup.git newdirectory 
cd newdirectory 
git fetch origin refs/remotes/*:refs/remotes/* 
git init 

git branch -aは私のリモートブランチの全てを示しています。

ここでgit initが必要な場合、またはgit init --bareの亜種(下記のシェルスクリプトのコメント行を参照)にのみ必要な場合はわかりませんが、それを残すことはないと確信していますそれが必要でないならば。

これを行う主な理由は、SVN trunkを指しているだけでなく、SVNの履歴全体を解析する必要がなく、masterを持っていて、多くの履歴を持つプロジェクトでは非常に遅いと枝)。だから私のSVNの情報をコピーする:既存のgitのSVNリポジトリから、このようなバックアップを作成するためには

#!/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 init -s "svn://mysvnhost/mysvnrepo/myproject" 
git svn fetch 
git checkout master 

、私はシェルスクリプトを作成し

あなたのコマンドを改善する方法は2つあります
# create a bare backup repo at [email protected]:mybackup.git 
git remote add backup [email protected]:mybackup.git 
git config remote.backup.fetch do_not_fetch_from_backup 
git config remote.backup.push '+refs/remotes/*:refs/remotes/*' 
git push backup 
関連する問題