svn存储库的只读git镜像

时间:2009-11-07 12:48:33

标签: svn git post-commit

设置现有svn存储库的只读git镜像的最佳方法是什么,并设置post-commit钩子,这样每当有人提交svn时,git镜像会自动更新?主要是,我想在服务器上运行一次git-svn clone,然后让人们从git中检出,而不必自己克隆整个svn存储库。

2 个答案:

答案 0 :(得分:4)

我在使用SVN的项目上执行此操作(推送到github上的公共存储库)。我没有SVN提交钩子,但这是在一个cron工作:

#!/bin/bash

repo=/path/to/my-mirror.git
lockfile="$repo/cron-lock"

if ! lockfile -r1 "$lockfile";then
        exit 1
fi

export GIT_DIR=$repo
# update refs/remotes/git-svn:
git svn fetch -q
# make 'master' match the git-svn branch:
git fetch "$repo" refs/remotes/git-svn:refs/heads/master
# publish to github
git push github master

rm -f "$lockfile"

如果从SVN提交挂钩而不是cron作业触发它,它应该可以工作。

当然,您需要使用github设置名为git remote add github [...]的遥控器。我正在使用的git存储库是一个“裸”存储库(请参阅git init --bare)。

答案 1 :(得分:2)

设置Svn / Git镜像(可写)的最佳方法是使用SubGit - 这是专门为此任务开发的工具。免责声明:我是这个工具的开发者。

相关问题