问题
Summary:
What I'd like to accomplish is to periodically push a bare Git repository into Subversion so others can examine it, using an unattended script. I don't need the opposite direction, SVN -> Git.
I hope someone will help me get this done. The other threads I've seen are oh-so-close to what I need, but none have the full, plausible solution. Pushing an existing git repository to SVN was extremely helpful.
My problem:
My employer maintains a Subversion server that has offsite backup, has redundancies, and is accessible by a web interface so my coworkers and managers can do casual reviews.
I have six projects under Git. (I have multiple machines, I do lots of speculative branching, and I commit frequently. Also, Xcode just works better with Git. Our SVN administrator agrees that Git is all but nonnegotiable for me.) I've been doing this by keeping a bare repo on my desktop machine (owned by my employer and on its premises) which all working copies track.
My employer would really prefer I didn't do that; if he could provide an IT-grade Git server, he would. His compromise is that I find a way to get a launchd
(cron
) task to sync my desktop's bare Git repo to a parallel repo on the SVN server.
My proposed approach (probably unsatisfactory):
I haven't found any guides to cloning bare Git repos to Subversion, still less doing it unattended. My guess is that I have to do everything by way of a working copy, for which SVN syncing (but maybe not automation) is a solved problem.
My naïve process is:
- Clone a working copy that is never edited into
/dont-touch
, from the bare repo. - While in the no-edits
/dont-touch
directory,git svn init <svn-url> -s
- Do the necessary
git svn fetch
andgit svn rebase
dance. - Every night, per a script fired by
launchd
:
4.1.cd /dont-touch
4.2.git fetch
4.3.git svn dcommit
The problems, as I see them:
I'm ignorant
Enough said.
This category includes all the things I haven't thought of.
Interactivity
Our hope is that we can set this up, let the sync script fire every 24 hours, and forget it.
SVN authentication will, I assume, be cached and take care of itself after the first time it goes through, during the manual (1-3) setup. Git authentication would not be an issue, as the dont-touch
working copy would be owned by the same user as the bare repo, and can be reached by file:///
.
But my impression of syncing Git to SVN is that it is fragile, and will need interactive nips and tucks to avoid damaging the SVN repo, much less simply getting it to work.
回答1:
You may have a look at SubGit as git-svn replacement. Since 2.0 it allows to link local Git with remote Subversion repository. You run once:
$ subgit configure --svn-url <URL_of_SVN_project_root> repos.git
# edit repos.git/subgit/config, repos.git/subgit/authors.txt, and repos.git/subgit/passwd
$ subgit install repos.git
# now just work with repos.git as with usual git repository, but prefer "git pull --rebase" rather that "git pull" and "git merge --no-ff" rather than "git merge"
where URL_of_SVN_project_root is the URL that contains trunk/branches/tags directories.
Then clone the repository 'repos.git' and push/pull from/to it (optionally setup the working copy git config this way). Special Git hooks in 'repos.git' will synchronize it with SVN. Note that currently SubGit 2.0 is at eap stage, but I think it's more reliable that git-svn setup you described.
来源:https://stackoverflow.com/questions/13654129/automatically-sync-git-to-svn