简体   繁体   中英

Mirror git branch to svn repo

I'm looking for a way of setting up an existing git repository (cloned from a central repo hosted on Atlassian stash) so that changes from a specfic branch are synchronised to a path on an SVN repository. I'm not particularly interested in fetching changes back from SVN or synchronising branches and tags; I just want to have an SVN "mirror" of one of my branches.

After reading the git-svn man page and various other sources I got as far as setting up the svn repo with git svn init, but it will refuse to dcommit anything:

$ git --version
git version 1.9.5.msysgit.0
$ git clone ssh://git@stash-server.mydomain.com:4321/myproject/playground.git
Cloning into 'playground'...
$ cd playground
$ svn mkdir --parents https://svn-server.mydomain.com:5432/svn/playground/trunk -m "Importing git repo" 
Committed revision 15900.
$ git svn init https://svn-server.mydomain.com:5432/svn/playground/trunk
$ git svn fetch
W: Ignoring error from SVN, path probably does not exist: (175007): HTTP Path Not Found: REPORT request failed on '/svn/145273/!svn/bc/100/playground/trunk': '/svn/145273/!svn/bc/100/playground/trunk' path not found
W: Do not be alarmed at the above message git-svn is just searching aggressively for old history.
This may take a while on large repositories
r15900 = 1ad941791edb06c4df8281cd31e69ce5d508e728 (refs/remotes/git-svn)
$ git svn dcommit
Unable to determine upstream SVN information from HEAD history.
Perhaps the repository is empty. at C:\Program Files (x86)\Git/libexec/git-core\git-svn line 856.

"Perhaps the repository is empty" -> of course it is, I'm trying to "clone" a git branch into svn. Any idea what I'm doing wrong here?

You might want to check out SubGit and their add-on for Atlassian Stash. It neatly takes care of mirroring Git to SVN while you transition.

Disclosure: I work for Atlassian

Found answer here: http://eikke.com/importing-a-git-tree-into-a-subversion-repository/

This fails since the git svn command can't figure out which commits to push: there's no link between our original Git repository and the Subversion heads.

To fix this, we can use a Git graft to link them. We'll tell Git the commit which created the SVN folder in which we want to store the project is the parent commit of the first commit in our Git repository:

$ git show-ref trunk
741ab63aea786882eafd38dc74369e651f554c9c refs/remotes/trunk
$ git log --pretty=oneline master | tail -n1
88464cfdf549a82b30ee7c52e53e2b310f0d9ec4 Initial version
$ echo "88464cfdf549a82b30ee7c52e53e2b310f0d9ec4 741ab63aea786882eafd38dc74369e651f554c9c" >> .git/info/grafts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM