本文介绍了自动将Git同步到SVN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

摘要:

我要完成的工作是定期将 bare Git存储库推送到Subversion中,以便其他人可以使用无人值守的脚本对其进行检查.我不需要相反的方向,SVN-> Git.

我希望有人能帮助我完成这项任务.我见过的其他线程太接近我所需要的了,但是没有一个线程有完整,合理的解决方案. 将现有git存储库推送到SVN 非常有用.

我的问题:

我的雇主维护着一个Subversion服务器,该服务器具有异地备份,冗余和可通过Web界面访问,因此我的同事和经理可以进行临时审核.

我在Git下有六个项目. (我有多台机器,我做很多推测性分支,而且我经常提交.而且,Xcode可以更好地与Git一起使用.我们的SVN管理员同意Git对我来说几乎是不可商议的.)所有工作副本都在跟踪的台式机(由我的老板及其驻地拥有)上的裸回购.

我的老板真的希望我不这样做;如果他可以提供IT级的Git服务器,他会的.他的妥协是,我找到一种方法来获取launchd(cron)任务,以将桌面的裸机Git存储库同步到SVN服务器上的并行存储库.

我建议的方法(可能不令人满意):

我还没有找到将裸Git仓库克隆到Subversion的任何指南,更不用说在无人值守的情况下进行了.我的猜测是,我必须通过工作副本来完成所有工作,对于该问题,SVN同步(但可能不是自动化)是一个已解决的问题.

我的天真过程是:

  1. 从裸仓库克隆从未编辑过的工作副本到/dont-touch的工作副本.
  2. 在非编辑/dont-touch目录中的git svn init <svn-url> -s
  3. 进行必要的git svn fetchgit svn rebase跳舞.
  4. 每晚,根据launchd触发的脚本:
    4.1. cd /dont-touch
    4.2. git fetch
    4.3. git svn dcommit

问题,正如我所看到的:

我无知

足够了.

此类别包括我没有想到的所有内容.

互动性

我们希望我们可以进行设置,让同步脚本每24小时触发一次,然后忘记它.

我认为,在手动(1-3)设置期间,SVN身份验证将在第一次通过后进行缓存并自行处理. Git身份验证不会成为问题,因为dont-touch工作副本将与裸仓库由同一用户拥有,并且可以由file:///进行访问.

但是我将Git同步到SVN的印象是它很脆弱,并且需要交互式的压区和缝隙来避免损坏SVN存储库,更不用说使其正常工作了.

解决方案

您可能以git- svn替换.从2.0开始,它允许将本地Git与远程Subversion存储库链接.您运行一次:

$ 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"

其中URL_of_SVN_project_root是包含主干/分支/标签目录的URL.

然后克隆存储库'repos.git'并从中推入/拉入(可选地,设置工作副本git config 这种方式). 'repos.git'中的特殊Git钩子会将其与SVN同步.请注意,当前SubGit 2.0处于eap阶段,但是我认为您描述的git-svn设置更加可靠.

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:

  1. Clone a working copy that is never edited into /dont-touch, from the bare repo.
  2. While in the no-edits /dont-touch directory, git svn init <svn-url> -s
  3. Do the necessary git svn fetch and git svn rebase dance.
  4. 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.

解决方案

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.

这篇关于自动将Git同步到SVN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 19:29