---
title: "svn2git"
canonical: "https://wiki.kicco.com/space/BIT/121274394/svn2git"
format: markdown
---
> Macro (toc)

## **개요**

---

SVN 저장소를 Git으로 이관하려면 svn2git 패키지를 이용한다.

## **사전요구 사항**

---

svn2git은 ruby로 개발된 패키지 입니다. 사용을 하기 위해서는 사전에 ruby가 설치되어 있어야 한다. ruby설치와 관려된 문서는 아래 링크를 참조한다.

[https://www.ruby-lang.org/ko/documentation/installation/](https://www.ruby-lang.org/ko/documentation/installation/)

svn2git 설치와 관련된 문서는 아래 링크를 참조한다.

[https://docs.gitlab.com/ee/user/project/import/svn.html](https://docs.gitlab.com/ee/user/project/import/svn.html)

## **이관**

---

1. svn 저상소 checkout하기 위한 폴더를 생성하고 생성된 폴더로 이동한다.

```shell
cd sample
```

2. 작업자 정보를 이관하기 위해 .svn2git 폴더를 생성하고 생성된 폴더에 authors 파일을 생성한다. (아래 작업자 이관 항목 참조)

```shell
mkdir ~/.svn2git
vi ~/.svn2git/authros
```

3. svn2git 명령어를 이용해서 svn 저정소의 파일을 내려받고 로컬 git 저장소로 변환한다.

```shell
svn2git SVN_URL  --username NAME  --authors ~/.svn2git/authors
```

4. 그외 자세한 옵션은 아래표를 참조 한다.

|  |
| --- |
| `Usage: svn2git SVN_URL [options]Specific options:        --rebase                     Instead of cloning a new project, rebase an existing one against SVN        --username NAME              Username for transports that needs it (http(s), svn)        --password PASSWORD          Password for transports that need it (http(s), svn)        --trunk TRUNK_PATH           Subpath to trunk from repository URL (default: trunk)        --branches BRANCHES_PATH     Subpath to branches from repository URL (default: branches); can be used multiple times        --tags TAGS_PATH             Subpath to tags from repository URL (default: tags); can be used multiple times        --rootistrunk                Use this if the root level of the repo is equivalent to the trunk and there are no tags or branches        --notrunk                    Do not import anything from trunk        --nobranches                 Do not try to import any branches        --notags                     Do not try to import any tags        --no-minimize-url            Accept URLs as-is without attempting to connect to a higher level directory        --revision START_REV[:END_REV]                                     Start importing from SVN revision START_REV; optionally end at END_REV    -m, --metadata                   Include metadata in git logs (git-svn-id)        --authors AUTHORS_FILE       Path to file containing svn-to-git authors mapping (default: ~/.svn2git/authors)        --exclude REGEX              Specify a Perl regular expression to filter paths when fetching; can be used multiple times    -v, --verbose                    Be verbose in logging -- useful for debugging issues        --rebasebranch REBASEBRANCH  Rebase specified branch.    -h, --help                       Show this message` |


5. trunk, branches, tags 구조를 사용하지 않는 SVN 저장소는 **--notrunk, ** **--nobranches, ** **--notags **옵션을 사용해야 한다.

6. 생성한 로컬 git 저장소를 remote에 push

```shell
git remote add origin GIT_URL
git push -u origin master
```

7. svn에 tags가 있을 경우

```shell
git push --tags origin
```

8. 모든 브랜치 푸시

```shell
git push --all origin
```

## **Authors 파일**

---

매핑 파일은 svn id = git 계정 정보를 이력한다. svn 저상소 checkout하기 위한 폴더를 생성하고 생성된 폴더로 이동한다.

```
Hong = Hong <hong@never.com>
```

svn의 commit id 정보는 svn 로컬 저장소에서 아래 명령어를 이용해서 확인할 수 있다.

```shell
svn log|grep "^r[0-9]"|awk -F\| '{print $2}'| sed -e 's/^[ \t]*//'|sort|uniq
```