---
slug: "巨大なSVNリポジトリの一部をGitリポジトリにする"
title: "Converting a Large SVN Repository Segment into a Git Repository"
description: "Migrate one subdirectory of a huge SVN repository into Git. `git svn clone` alone pulls in docs/dumps too — this post shows how to exclude those paths."
url: "https://www.ytyng.com/en/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/Etc"]
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: "en"
---

# Converting a Large SVN Repository Segment into a Git Repository

<div class="document">

<div class="section" id="id1">
<h3>Prerequisites</h3>
<ul class="simple">
<li>There is a large SVN repository, and one of the directories within it is the source code directory. The other directories contain documents and mysqldumps.</li>
<li>We have been operating by performing an SVN checkout and updating only the source code directory.</li>
<li>We want to migrate to Git.</li>
<li>However, the directories other than the source code directory are large in size, so we do not want to include them in the repository.</li>
</ul>
</div>

<div class="section" id="id2">
<h3>What We Tried</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>→ This results in a huge myproject repository that includes documents and mysqldumps.</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>This error appears, and the clone cannot be completed.</p>
</div>

<div class="section" id="id3">
<h3>How to Achieve It</h3>
<p>First, clone the repository as is.</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>At this point, take a full copy of the local repository.</p>
<pre class="literal-block">cd ..
cp -r myproject myproject_work
cd myproject_work
</pre>
<p>Use git filter-branch to keep only the commits for the source code!</p>
<pre class="literal-block">git filter-branch --subdirectory-filter source HEAD
</pre>
<p>Remove unnecessary directories (optional).</p>
<pre class="literal-block">rm -rf my-documents
rm -rf my-mysqldumps
</pre>
<p>The repository is now complete. Push it.</p>
<pre class="literal-block">git remote add origin my-remote-repo
git push origin master
</pre>
<p>When there are updates to the SVN repository
If the SVN repository is updated, perform a git svn rebase in the repository before filter-branch, and then follow the same steps to incorporate the changes into the Git repository.</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>
