问题
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).
回答1:
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
...
回答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:
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
.
来源:https://stackoverflow.com/questions/9642551/import-separate-svn-directories-as-git-branches