Day 29: Subversion 프로젝트를 Git 리포지토리로 가져오는 방법
많은 조직이 여전히 Subversion(SVN)을 사용하지만 Git으로 마이그레이션하기를 원합니다. 이 글에서는 이력을 보존하면서 SVN 리포지토리를 Git으로 가져오는 방법을 설명하겠습니다.
왜 SVN에서 Git으로 마이그레이션할까요?
Git의 장점:
- 분산 워크플로
- 빠른 작업 속도(로컬)
- 더 나은 브랜치와 병합
- 오프라인 작업
- 더 유연한 워크플로
- 더 나은 도구와 생태계
어려움:
- 학습 곡선
- 다른 개념
- 워크플로 변화
- 팀 적응
마이그레이션 전략
1. 빠른 가져오기(단순)
빠르지만 일부 SVN 메타데이터가 유실됩니다.
# Clone entire SVN repository
git svn clone http://svn.example.com/repo
# Or specify trunk/branches/tags structure
git svn clone http://svn.example.com/repo --trunk=trunk --branches=branches --tags=tags
2. 적절한 가져오기(권장)
저자, 브랜치, 태그를 보존합니다.
# Create authors file
# Map SVN users to Git users
echo "svnuser1 = John Doe <john@example.com>" >> authors.txt
echo "svnuser2 = Jane Smith <jane@example.com>" >> authors.txt
# Clone with authors file
git svn clone http://svn.example.com/repo \
--authors-file=authors.txt \
--trunk=trunk \
--branches=branches \
--tags=tags \
--no-metadata
3. svn2git 사용하기(가장 쉬움)
svn2git를 설치합니다.
# On Mac
brew install svn2git
# On Linux
gem install svn2git
저자 파일을 만듭니다.
# Generate authors list from SVN
svn log -q http://svn.example.com/repo | \
awk -F '|' '/^r/ {print $2}' | \
sort -u > authors.txt
# Edit authors.txt to add email addresses
# Format: svnuser = Full Name <email@example.com>
마이그레이션을 수행합니다.
# Create new directory
mkdir git-repo
cd git-repo
# Run migration
svn2git http://svn.example.com/repo \
--authors authors.txt
단계별 마이그레이션 과정
1단계: 준비
1. Identify SVN repository structure
2. Create authors mapping file
3. Decide on Git repository structure
4. Plan branch/tag strategy
5. Communicate with team
2단계: 테스트 마이그레이션
# Do test migration first
git svn clone http://svn.example.com/repo test-migration
# Verify:
- Commit history
- Branches
- Tags
- File contents
3단계: 저자 파일 만들기
SVN 저자를 추출합니다.
svn log -q http://svn.example.com/repo | \
grep "^r" | \
awk '{print $3}' | \
sort -u > svn-authors.txt
Git 형식으로 변환합니다.
# authors.txt
jdoe = John Doe <john.doe@example.com>
jsmith = Jane Smith <jane.smith@example.com>
admin = Administrator <admin@example.com>
4단계: 마이그레이션 수행
# Clone SVN repository
git svn clone http://svn.example.com/repo \
--authors-file=authors.txt \
--stdlayout \
migrated-repo
cd migrated-repo
# Convert SVN tags to Git tags
git for-each-ref refs/remotes/tags | cut -d / -f 4- | \
while read tagname; do
git tag "$tagname" "refs/remotes/tags/$tagname"
git branch -r -d "tags/$tagname"
done
# Convert SVN branches to Git branches
git for-each-ref refs/remotes/origin | cut -d / -f 4- | \
while read branchname; do
git branch "$branchname" "refs/remotes/origin/$branchname"
done
# Remove SVN remote
git remote rm origin
5단계: Git 리모트에 Push하기
# Add Git remote
git remote add origin https://github.com/your-org/repo.git
# Push all branches
git push -u origin --all
# Push all tags
git push -u origin --tags
특수한 경우 처리하기
대규모 리포지토리
대규모 리포지토리는 점진적으로 가져옵니다.
# Start from revision 1000
git svn clone http://svn.example.com/repo \
-r 1000:HEAD \
--authors-file=authors.txt
경로 무시하기
SVN ignore를 기반으로 .gitignore를 만듭니다.
# Extract SVN ignores
git svn show-ignore > .gitignore
# Commit
git add .gitignore
git commit -m "Add .gitignore from SVN"
바이너리 파일
SVN과 Git은 바이너리를 다르게 처리합니다.
# For large binary files, consider Git LFS
git lfs install
git lfs track "*.psd"
git lfs track "*.zip"
SVN 브리지(git-svn)
전환하는 동안 SVN을 계속 사용합니다.
# Clone with git-svn
git svn clone http://svn.example.com/repo
# Work normally with Git locally
# Get SVN updates
git svn rebase
# Push to SVN
git svn dcommit
워크플로:
# Pull from SVN
git svn rebase
# Make changes
git add .
git commit -m "Changes"
# Push to SVN
git svn dcommit
마이그레이션 후 작업
1. 마이그레이션 검증
# Check commit count
git log --oneline | wc -l
# Compare with SVN
# Should match or be close
# Check specific files
git log -- path/to/file.txt
svn log path/to/file.txt
# Verify branches
git branch -a
# Verify tags
git tag
2. CI/CD 업데이트
- 빌드 스크립트를 업데이트합니다
- VCS URL을 변경합니다
- 배포 파이프라인을 업데이트합니다
- 모든 자동화 과정을 테스트합니다
3. 팀 교육
- Git 기초 워크숍
- 새 워크플로 문서
- 실습
- 전환 기간 동안 지원
4. 문서 업데이트
- README를 업데이트합니다
- 체크아웃 안내를 변경합니다
- 기여 가이드라인을 업데이트합니다
- 새 워크플로를 문서화합니다
비교: SVN vs Git 명령어
# Checkout
SVN: svn checkout
Git: git clone
# Update
SVN: svn update
Git: git pull
# Commit
SVN: svn commit
Git: git commit + git push
# Status
SVN: svn status
Git: git status
# Log
SVN: svn log
Git: git log
# Branch
SVN: svn copy .../trunk .../branches/name
Git: git checkout -b name
# Tag
SVN: svn copy .../trunk .../tags/v1.0
Git: git tag v1.0
# Merge
SVN: svn merge
Git: git merge
# Diff
SVN: svn diff
Git: git diff
문제 해결
문제: 커밋 누락
# Check SVN revision range
git svn log | head -n 20
# Re-clone from specific revision
git svn clone -r START:HEAD ...
문제: 저자 매핑 오류
# Add missing authors to authors.txt
# Re-run migration
문제: .git 디렉터리가 너무 큼
# Garbage collection
git gc --aggressive --prune=now
# Consider shallow clone for very old history
오늘의 요약
SVN에서 Git으로의 마이그레이션에는 계획과 신중한 실행이 필요합니다. svn2git 같은 적절한 도구를 사용하고 저자 매핑을 유지하면 원활한 전환을 보장할 수 있습니다. 시간을 들여 마이그레이션을 테스트하고, 결과를 검증하고, 팀에게 Git 워크플로를 교육하세요.
오늘 배운 Git 명령어와 매개변수를 다시 정리하겠습니다.
- git svn clone
- git svn rebase
- git svn dcommit
- git svn show-ignore
- git for-each-ref
- git gc –aggressive