I have an SVN repo with a layout like
project1/trunk
project1/branches
project1/tags
project2/trunk
project2/branches
project2/tags
etc.
For a number of reasons, I'd like a git-svn repo that allows me to work on any of these projects and fetch/dcommit from/to all of them at once. Is this kind of thing possible? I know I could just git-svn clone the whole thing without specifying branches, tags, and trunk, but then I'd lose a lot of the advantage of using git.
# Clone a repo with standard SVN directory layout (like git clone): git svn clone http://svn.example.com/project --stdlayout --prefix svn/ # Or, if the repo uses a non-standard directory layout: git svn clone http://svn.example.com/project -T tr -b branch -t tag --prefix svn/ # View all branches and tags you have ...
The git svn clone command transforms the trunk, branches, and tags in your SVN repository into a new Git repository. Depending on the structure of your SVN repo, the command needs to be configured differently.
Use git-svn, it is really simple. First clone your repository with git svn clone then you can git svn dcommit your work or git svn rebase it on the latest changes. Make sure your history is always linear by always rebasing your local branches on master so that you can merge them with git merge --ff-only .
This is how I did it. There may be simpler ways, though.
Select the first project with the standard layout you'd like to work on and git svn clone
it:
git svn clone --stdlayout http://sample.com/svn/repository-name/project-name repository-name
Go into the repository-name
directory and edit its .git/config
file. You could also do this with git-config
commands, but I find it easier in a text editor.
You'll see an [svn-remote "svn"]
section already defined for your first project. Rename the svn-remote
to something more unique than "svn"
, probably the same as your project name. E.g., [svn-remote "project-name"]
.
Make more [svn-remote "project-name"]
sections for each project, following the template of the first one. Give each one a unique name! You'll need to change the fetch
, branches
, and tags
settings to use the correct Subversion directory names for each project.
Once you're done, save your file and run git svn fetch --fetch-all
. The other projects will be fetched as remotes in your local repository.
To switch your master
between projects, do a git reset --hard other-project-name/trunk
, just like if you were switching to work on any other remote Subversion branch.
To get around the issue of checking out multiple projects simultaneously, git-new-workdir can be used to check out multiple working directories from the same git repository, see https://github.com/git/git/blob/master/contrib/workdir/git-new-workdir
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With