Skip to content

Instantly share code, notes, and snippets.

@ikaruce
Created February 3, 2015 08:06
Show Gist options
  • Save ikaruce/9c8dc57849e003df6fdc to your computer and use it in GitHub Desktop.
Save ikaruce/9c8dc57849e003df6fdc to your computer and use it in GitHub Desktop.
SVN에서 Git으로 전환하기(브랜치와 태그 보전하면서)

SVN에서 Git으로 전환하기

(원문 http://www.sailmaker.co.uk/blog/2013/05/05/migrating-from-svn-to-git-preserving-branches-and-tags-3/ )

브랜치와 태그 보전하면서

git svn 을 사용해서 SVN에서 브랜치와 태그를 보존하면서 Git으로 전환하는 것을 설명한다.

로컬 스테이징 리파지토리로 import

로컬 스테이징 폴더 생성
$ mkdir staging
$ cd staging
# 'staging'이라고 지정했지만, 반드시 'staging'이라고 할 필요는 없음.  
# 하지만 아래에서는 'staging'이라고 지칭할 것임.
git svn 초기화
# [[SVN_URL]] 변경
$ git svn init [[SVN_URL]] -T Trunk -b Branches -t Tags --prefix=svn/
설정 확인
$ git config --local --list

출력된 것중에 아래와 같은 내용이 있음.

svn-remote.svn.url=svn://svn.example.com
svn-remote.svn.fetch=some/path/trunk:refs/remotes/svn/trunk
svn-remote.svn.tags=some/path/tags/*:refs/remotes/svn/tags/*
스테이징 서버로 SVN 받아오기.
$ git svn fetch

리파지토리 크기와 전송속도에 따라 다르지만, 몇분에서 몇시간 사이로 소모된다.

스테이징 리파지토리 테스트
$ git status 

결과는

# On branch master
nothing to commit (working directory clean)

그리고 브랜치를 확인해본다.

$ git branch -a

결과는 아래와 비슷한 모양이다.

* master
  remotes/svn/tags/0.1.0
  remotes/svn/tags/0.2.0
  remotes/svn/tags/0.3.0
  remotes/svn/tags/0.4.0
  remotes/svn/trunk

결과에 브랜치가 없지만, 브랜치가 있는경우 브랜치도 확인할 수 있다.

SVN 태그와 브랜치를 Git 태그와 브랜치로 전환.

SVN 브랜치.

원격 SVN 브랜치를 로컬 Git 브랜치로.

$ for branch in `git branch -r | grep "branches/" | sed 's/ branches\///'`; do
  git branch $branch refs/remotes/$branch
done
SVN 태그

SVN 태그는 Git 브랜치로 또는 Git 태그로 변환될 수 있다. 이거는 순전히 마음먹기(정책)에 달려있다.

SVN 태그를 Git 태그로 변환할때.
$ for tag in `git branch -r | grep "tags/" | sed 's/ tags\///'`; do
  git tag -a -m"Converting SVN tags" $tag refs/remotes/$tag
done
SVN 태그를 Git 브랜치로 변환할때
$ for tag in `git branch -r | grep "tags/" | sed 's/ tags\///'`; do
  git branch $tag refs/remotes/$tag
done

로컬에서 테스트

원격저장소로 푸시하기 전에 로컬 Git 리파지토리로 푸시하고 클론하여 결과를 테스트

로컬 Git bare 리파지토리 생성.
$ cd ~
$ mkdir test
$ cd test
$ git init --bare

~/test 라는 bare 리파지토리가 생성됨.

테스트 Git 리파지토리로 push
$ cd ~/staging
$ git remote add test `~/test`
$ git push --all test
$ git push --tags test

--all 옵션이 태그는 푸시하지 않음, 그래서 푸시를 나누어서 해줘야함.

테스트 리파지토리로부터 clone
$ cd ~
$ mkdir aclone
$ cd aclone
$ git clone ~/test

테스트 해보고 이상 없으면 원격 저장소로 Push 하면 된다.

스테이징 리파지토리를 원격 저장소로 push
$ cd ~/staging
$ git remote add origin [[REAL_HOST_URL]]
$ git push --all origin
$ git push --tags origin 

origin 이라 지칭했지만 어떤걸 사용해도 된다. [[REAL_HOST_URL]]은 실제 사용할 원격 리파지토리 주소를 사용해야 한다.

뒷정리

이제 마무리 작업이 남아있다. 테스트로 만들었던 리파지토리들과 스테이징 리파지토리를 삭제한다.

테스트 원격 리파지토리 삭제
$ cd ~/staging
$ git remote rm test

이제 스테이징 리파지토리에 test라는 원격리파지토리는 삭제됬다.

Clone 했던 리파지토리 삭제
$ cd ~
$ rm -rf aclone
$ rm -rf test

테스트 리파지토리와 Clone 리파지토리를 삭제하고

스테이징 리파지토리 삭제( 선택적 )
$ cd ~
$ rm -rf staging

SVN 리파지토리를 계속해서 fetch해야 한다면 그대로 두는 것을 추천한다. 남겨둔다면, 초기에 fetch 하는 시간을 줄여준다. 하지만, 이제 더이상 fetch하지 않고 Git 리파지토리만 사용한다면 삭제해도 된다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment