I have an old SVN repository which contains a sub-directory of files I would like to import into an existing git repository, retaining history. How can this be done?
Suppose I have the existing SVN layout:
file:///svn
trunk
foo
bar
branches
And the following git layout:
file:///git
*master
baz
qux
And I want to import svn:///file/trunk/foo
into git, such that I have the following result:
file:///git
*master
foo
baz
qux
The solution I found requires the use of git-subtree, which is included as part of git contrib, or with the default git installation in some cases (such as with the git Debian package version 1.9 and later).
Clone the SVN repo with git-svn:
git svn clone -r 1540:HEAD \
--authors-file=authors.txt \
https://svn.host.com/repos/trunk/foo foo
Then in your main repo, create a new branch (optional, I suppose), and import the new partial repo using git-subtree:
git checkout -b foo
git subtree add --prefix foo /path/to/foo master