Converting a Large SVN Repository Segment into a Git Repository

PC/Etc
2013-08-30 19:51 (11 years ago) ytyng

Prerequisites

  • 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.
  • We have been operating by performing an SVN checkout and updating only the source code directory.
  • We want to migrate to Git.
  • However, the directories other than the source code directory are large in size, so we do not want to include them in the repository.

What We Tried

→ This results in a huge myproject repository that includes documents and mysqldumps.

Using higher level of URL:
W: Ignoring error from SVN, path probably does not exist: (175002): RA layer request failed: REPORT of '/svn/myproject

This error appears, and the clone cannot be completed.

How to Achieve It

First, clone the repository as is.

git svn clone -s --prefix svn/ http://my-svn-server/svn/myproject/ myproject
cd myproject
git svn create-ignore
git commit -m 'add gitignore'

At this point, take a full copy of the local repository.

cd ..
cp -r myproject myproject_work
cd myproject_work

Use git filter-branch to keep only the commits for the source code!

git filter-branch --subdirectory-filter source HEAD

Remove unnecessary directories (optional).

rm -rf my-documents
rm -rf my-mysqldumps

The repository is now complete. Push it.

git remote add origin my-remote-repo
git push origin master

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.

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
Current rating: 3

Comments

Archive

2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011