---
slug: "巨大なSVNリポジトリの一部をGitリポジトリにする"
title: "巨大なSVNリポジトリの一部をGitリポジトリにする"
description: "巨大な SVN リポジトリの一部 (サブディレクトリ) のみを Git に移行する方法。`git svn clone` だけではドキュメントを巻き込むので、不要パスを除外する手順。"
url: "https://www.ytyng.com/blog/巨大なSVNリポジトリの一部をGitリポジトリにする"
publish_date: "2013-08-30T10:51:21Z"
created: "2013-08-30T10:51:21Z"
updated: "2026-05-11T13:04:08.761Z"
categories: ["PCその他"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20230812/4f1d73cc2dcc4875909ca99519412900.png.webp?width=768"
has_video: false
has_music: false
video_urls: []
music_urls: []
lang: "ja"
---

# 巨大なSVNリポジトリの一部をGitリポジトリにする

<div class="document">


<div class="section" id="id1">
<h3>前提条件</h3>
<ul class="simple">
<li>大きなSVNリポジトリがあり、その中のディレクトリの1つのディレクトリがソースコードのディレクトリ。他はドキュメントやmysqldumpなんかが入っている</li>
<li>ソースコードのディレクトリのみ svn checkout して更新するという運用をしていた</li>
<li>git化したい</li>
<li>ただし、ソースコード以外のディレクトリはサイズが大きいので、リポジトリに含めたくない</li>
</ul>
</div>
<div class="section" id="id2">
<h3>試したこと</h3>
<ul class="simple">
<li>git svn clone -s --prefix svn/ <a class="reference external" href="http://my-svn-server/svn/myproject/">http://my-svn-server/svn/myproject/</a> myproject</li>
</ul>
<p>→ドキュメントやmysqldumpなんかが含まれた巨大な myproject リポジトリができる</p>
<ul class="simple">
<li>git svn clone -s --prefix svn/ <a class="reference external" href="http://my-svn-server/svn/myproject/source/">http://my-svn-server/svn/myproject/source/</a> myproject</li>
</ul>
<pre class="literal-block">Using higher level of URL:
W: Ignoring error from SVN, path probably does not exist: (175002): RA layer request failed: REPORT of '/svn/myproject
</pre>
<p>このようなエラーが出て、clone できない。</p>
</div>
<div class="section" id="id3">
<h3>実現方法</h3>
<p>まずはそのまま clone してくる。</p>
<pre class="literal-block">git svn clone -s --prefix svn/ http://my-svn-server/svn/myproject/ myproject
cd myproject
git svn create-ignore
git commit -m 'add gitignore'
</pre>
<p>一旦ここで、ローカルリポジトリの全コピーを取っておく</p>
<pre class="literal-block">cd ..
cp -r myproject myproject_work
cd myproject_work
</pre>
<p>git filter-branch でソースコードのコミットのみにする!</p>
<pre class="literal-block">git filter-branch  --subdirectory-filter source HEAD
</pre>
<p>不要なディレクトリを消しておく (やらなくても大丈夫だけど)</p>
<pre class="literal-block">rm -rf my-documents
rm -rf my-mysqldumps
</pre>
<p>リポジトリ完成。pushする</p>
<pre class="literal-block">git remote add origin my-remote-repo
git push origin master
</pre>
<p>SVNリポジトリに更新が入った場合
SVNリポジトリが更新された場合は、filter-branch する前のリポジトリで git svn rebase し、
後は同じようにすれば変更をgitリポジトリに取り込める。</p>
<pre class="literal-block">cd ..
rm -rf myproject_work
cd myproject
git svn rebase
cd ..
cp -r myproject myproject_work
cd myproject_work
git filter-branch  --subdirectory-filter source HEAD
rm -rf my-documents
rm -rf my-mysqldumps
git remote add origin my-remote-repo
git pull origin master
git push origin master
</pre>
</div>
</div>
