创造 svn branch 和使用 git-svn
This is the scenario, we have a project using svn as repository, which has a typical svn hierarchy like below:
project-name
|
|--- branches
|
|--- tags
|
|--- trunk
At the early stage, I checkout the trunk directory using git-svn to development the application.
The command I use is
git svn clone https://svn_add/svn/project_name/trunk
Recently, we needed to do some spikes on this project. We did them, and stashed each spike separately and locally.
Now, we wanted to commit each spike solution as a branch to the svn repository so that other developers in other places could see these solution.
I tried to use the command:
git svn branch -m "message" branch_name
but failed with the following information
Multiple branch paths defined for Subversion repository.
You must specify where you want to create the branch with the --destination argument.
After googling it, I checked my .git/config file and it looks like this:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[svn-remote "svn"]
url = https://svn_add/svn/project_name/trunk
fetch = :refs/remotes/git-svn
The url here points to the trunk directory and we need to specify branch destination here.
There are two ways to specify destination here.
In the first way, we could change the url back to the root directory and change the fetch directory. The modified file would like this:
[svn-remote "svn"]
url = https://svn_add/svn/project_name
fetch = trunk: refs/remotes/git-svn
branches = branches//*:refs/remotes/*
The second way is keeping the url and fetch untouched, just use relative path for the branches.
[svn-remote "svn"]
url = https://svn_add/svn/project_name/trunk
fetch = :refs/remotes/git-svn
branches = ../branches//*:refs/remotes/*
Both way could work, and I prefer the first one, because it looks much intuitive and don't have deal with relative directory.
If u r not sure about the result, u could add -n or --dry-run to test the result of the command, like this
git svn branch -n -m "message" branch_name
After I created a branch in the svn repository, I used command
git checkout -b local_branch_name remote_branch_name
to generate a new git branch locally which point to the branch I just created in the svn repository.
Now I could stash pop my spiking code and commit them to the branches in svn repository respectively.
Thanks GaoLi and her baby for their help.