3

I want to convert an existing SVN repository with a nonstandard layout that looks like this:

/ (root)
    /trunk
        regular trunk stuff that I would like to make the "master" branch
    /folder1
        files that I would like to make a separate branch "folder1"
    /folder2
        files that I would like to make a separate branch "folder2"
    /folder3
        files that I would like to make a separate branch "folder3"

... to a git repository, preserving history.

The catch is that folder1, folder2, and folder3 are not branched off from some point in trunk; they are a separate set of files, and they are not rooted in some convenient subdirectory (which is what makes this question differ from that one).

The desired git branch layout would look like:

master -----+------(trunk r1)------(trunk r2)----...
            |
folder1     \-----(folder1 r1)----(folder1 r2)---...
            |
folder2     \-----(folder2 r1)----(folder2 r2)---...
            |
folder3     \-----(folder3 r1)----(folder3 r2)---...

(Those revision numbers aren't actual svn revision numbers, just the number of the commit in that particular folder)

I've tried using git svn but it seems to want the branches to be in a single directory, containing one subfolder per branch. The problem is that if I do this, I would have to use / (the root directory) as branches directory, which would make trunk a separate branch (while I want to use it as the master branch).

Community
  • 1
  • 1
Etienne Perot
  • 4,764
  • 7
  • 40
  • 50

2 Answers2

4

You can do this by specifying multiple "trunks" to git svn by editing your .git/config file.

Initialize your git repository as normal:

git svn init {url-to-repository} -T trunk

Now if you edit your .git/config file, you'll find a section that looks something like the below:

[svn-remote "svn"]
    url = {url-to-repository}
    fetch = trunk:refs/remotes/trunk

Simply add some lines like the below, which will add each folder as a single folder to be fetched (as opposed to a folder of branches or a folder of tags to fetch):

    fetch = folder1:refs/remotes/folder1
    fetch = folder2:refs/remotes/folder2
    ...
me_and
  • 15,158
  • 7
  • 59
  • 96
2

I get the impression you really have four separate repositories that you want to track in a single git repository with each repo on its own branch. Not exactly how git is intended to be used but you can try this configuration setup:

mkdir repo
cd repo

git init .
touch README
git add README
git commit -m "Initial repository"

git checkout -b folder1
mkdir folder1
touch folder1/svn-code-here # Add SVN files to folder1
git add folder1
git commit -m "folder1 branch"

git checkout master

git checkout -b folder2
mkdir folder2
touch folder2/svn-code-here # Add SVN files to folder2
git add folder2
git commit -m "folder2 branch"

git checkout master

git checkout -b folder3
mkdir folder3
touch folder3/svn-code-here # Add SVN files to folder3
git add folder3
git commit -m "folder3 branch"

git checkout master
touch svn-trunk-code-here # Add SVN files to trunk
git add svn-trunk-code-here
git commit -m "trunk started"

This will create your three folder branches with only the shared README file from the initial trunk master created. This will create a branch graph like:

Git Branches

In the command sequence above, you would replace each touch svn-code-here with the commands and steps needed to extract the SVN files to the directory and add/commit to Git. When you checkout master none of the folder directories will be visible and you can use master as your trunk and switch branch to the folders as needed git checkout folder1.

tawman
  • 2,478
  • 1
  • 15
  • 24
  • The problem with this is that I don't think it's possible to import commits from SVN once the Git repository already has some commits in it :( That would effectively require adding commits from the past. That, and `git svn` assumes that it should check things out in the `master` branch, even when I am in the `folderx` branch. – Etienne Perot Mar 10 '12 at 06:12
  • @EtiennePerot each branch has its own timeline as they will never be merged back together with master, but I would recommend just each folder as a separate repository personally. – tawman Mar 10 '12 at 06:21
  • Yes, but they are all branching off from that one first commit in `master` where `README` is added, which means their timeline starts there. Given this, commits cannot be imported from SVN, because the SVN repository doesn't contain such a `README` file (so it doesn't really make sense to continue adding commits to a non-identical-to-the-SVN-repo tree) but also because those commits from SVN are much older (timestamp-wise) than that `README` commit in `master` (which was done just now) – Etienne Perot Mar 10 '12 at 06:24
  • Are you trying to preserve the svn history? If not, then no special import is needed. My approach was from a fresh history based on svn head. – tawman Mar 10 '12 at 06:42
  • Yes, I am trying to preserve all history, that's what makes it tricky. Sorry if that wasn't clear, I'll edit the question to mention that. – Etienne Perot Mar 10 '12 at 06:48